Advertisement
ya_makaron

рекурсия шереметы 3

Apr 30th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void func(char *str)
  4. {
  5.     static int len = (int)strlen(str) - 2;
  6.     static char new_str[128];
  7.     static int counter = 0;
  8.  
  9.     if (len > 0)
  10.     {
  11.         new_str[counter] = *str;
  12.         new_str[counter + 1] = '(';
  13.         counter++;
  14.         len -= 2;
  15.     }
  16.     else if (len < 0 && str[1])
  17.     {
  18.         new_str[counter] = *str;
  19.         new_str[counter + 1] = ')';
  20.         counter++;
  21.     }
  22.     else
  23.     {
  24.         new_str[counter] = *str;
  25.         len--;
  26.     }
  27.     counter++;
  28.    
  29.     str++;
  30.  
  31.     if (*str)
  32.         func(str);
  33.     else std::cout << new_str << std::endl;
  34. }
  35.  
  36. int main()
  37. {
  38.     func("card");
  39.     system("pause");
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement