Advertisement
bkit4s0

[ONP] error!!!

Apr 2nd, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Stack;
  5.  
  6. public class type {
  7.     public static void main(String args[]) throws NumberFormatException,
  8.             IOException {
  9.         String s;
  10.         Stack<Character> st;
  11.         // use scanner or use bufferedinputstream
  12.         /* Scanner scanner = new Scanner(System.in); */
  13.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  14.         int a = Integer.parseInt(in.readLine());
  15.         while ((a--) > 0) {
  16.             s = in.readLine();
  17.             st = new Stack<Character>();
  18.             for (int i = 0; i < s.length(); i++) {
  19.                 // use stack to solve problem
  20.                 if (s.charAt(i) == '(' || s.charAt(i) == ')')
  21.                     ;
  22.                 else if (s.charAt(i) == '+' || s.charAt(i) == '-'
  23.                         || s.charAt(i) == '*' || s.charAt(i) == '/'
  24.                         || s.charAt(i) == '^') {
  25.                     // pop stack and print to console
  26.                     if (!st.isEmpty())
  27.                         System.out.print(st.pop());
  28.                     st.push(s.charAt(i));
  29.                 } else if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
  30.                     // push s.charAt(i) to stack
  31.                     System.out.print(s.charAt(i));
  32.                     // System.out.print(st.pop());
  33.                 }
  34.             }
  35.             while (!st.isEmpty()) {
  36.                 System.out.print(st.pop());
  37.             }
  38.             // System.out.println(s);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement