fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string reverse(string::iterator& it)
  7. {
  8. char head = *(it++);
  9. if (head == 'b' || head == 'w')
  10. return string(1, head);
  11. string upperLeft = reverse(it);
  12. string upperRight = reverse(it);
  13. string lowerLeft = reverse(it);
  14. string lowerRight = reverse(it);
  15.  
  16. return "x" + lowerLeft + lowerRight + upperLeft + upperRight;
  17. }
  18.  
  19. int main(void)
  20. {
  21. int C; cin >> C; while(C--)
  22. {
  23. string picture;
  24. cin >> picture;
  25. string::iterator it = picture.begin();
  26. cout << reverse(it) << endl;
  27. }
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5424KB
stdin
4
w
xbwwb
xbwxwbbwb
xxwwwbxwxwbbbwwxxxwwbbbwwwwbb
stdout
w
xwbbw
xxbwwbbbw
xxwbxwwxbbwwbwbxwbwwxwwwxbbwb