fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. void get_levels(string& Expr, int& index, int depth, vector<string>& Answer) {
  8. Answer[depth] += Expr[index];
  9. index--;
  10. if (isupper(Expr[index+1])) {
  11. get_levels(Expr, index, depth + 1, Answer);
  12. get_levels(Expr, index, depth + 1, Answer);
  13. }
  14. }
  15.  
  16.  
  17. int main() {
  18. int n, index;
  19. cin >> n;
  20. string Expr;
  21. for (int k = 0; k < n; k++) {
  22. cin >> Expr;
  23. vector<string> Answer(Expr.size(), "");
  24. index = Expr.size() - 1;
  25. get_levels(Expr, index, 0, Answer);
  26. for (int k = Expr.size() - 1; k >= 0; k--)
  27. cout << Answer[k];
  28. cout << endl;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3420KB
stdin
5
x
xyP
xyPzW
xyPzwIM
abcABdefgCDEF
stdout
x
yxP
yxzPW
wzyxIPM
gfCecbDdAaEBF