fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Index {
  6. int in;
  7. public Index(int a) {
  8. in = a;
  9. }
  10. }
  11.  
  12. class Main
  13. {
  14. public static void get_levels(char[] Expr, Index index, int depth, String[] Answer) {
  15. Answer[depth] += Expr[index.in];
  16. index.in--;
  17. if (Character.isUpperCase(Expr[index.in + 1])) {
  18. get_levels(Expr, index, depth + 1, Answer);
  19. get_levels(Expr, index, depth + 1, Answer);
  20. }
  21. }
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. Scanner in = new Scanner(System.in);
  25. int n = in.nextInt();
  26. String str = in.nextLine();
  27.  
  28. for (int k = 0; k < n; k++) {
  29. str = in.next();
  30. char[] Expr = str.toCharArray();
  31. String[] Answer = new String[Expr.length];
  32. Arrays.fill(Answer, "");
  33. Index index = new Index(Expr.length - 1);
  34. get_levels(Expr, index, 0, Answer);
  35. for (int j = Expr.length - 1; j >= 0; j--)
  36. System.out.print(Answer[j]);
  37. System.out.println();
  38. }
  39. }
  40. }
Success #stdin #stdout 0.14s 321280KB
stdin
5
x
xyP
xyPzW
xyPzwIM
abcABdefgCDEF
stdout
x
yxP
yxzPW
wzyxIPM
gfCecbDdAaEBF