Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <string.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. char* fun(char *a, char *b, int n)
  10. {
  11.     string a_str, b_str(b), ans(a);
  12.     int p = 0;
  13.     for (int i = 0; i < n - 1; i++)
  14.     {
  15.         int count = 0, it;
  16.         a_str = ans;
  17.         while ((p = a_str.find('X')) != string::npos)
  18.         {
  19.             a_str[p] = '#';
  20.             it = p + (b_str.size() - 1)*count;
  21.             ans.insert(it + 1, b_str);
  22.             ans.erase(it, 1);
  23.             count++;
  24.         }
  25.     }
  26.  
  27.     char * str = new char[ans.size() - 1];
  28.     strcpy(str, ans.c_str());
  29.     return str;
  30. }
  31.  
  32. int main()
  33. {
  34.     char a[200]="F+XF+F+XF", b[200]="XF-F+F-XF+F+XF-F+F-X";
  35.  
  36.     printf("%s", fun(a, b, 2));
  37.  
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement