Advertisement
lameski

kolokviumska zagradi

Aug 13th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Stack;
  3.  
  4. public class Zagradi_ispitna {
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7.  
  8. String s = in.nextLine();
  9. Stack<Character> st = new Stack<Character>();
  10. boolean test = false;
  11. boolean test2 = false;
  12. boolean fin = false;
  13. for(int i=0; i<s.length(); i++)
  14. {
  15. st.push(s.charAt(i));
  16. if(test && st.peek()=='(')
  17. test2 = true;
  18. if(Character.isAlphabetic(st.peek()) || st.peek()=='+')
  19. {
  20. st.pop();
  21. test = true;
  22. continue;
  23. }
  24.  
  25. if(st.peek()==')' && (test || test2))
  26. {
  27. st.pop();st.pop();
  28. if(!test)
  29. {
  30. test2 = false;
  31. }
  32. test = false;
  33. }
  34. else if(st.peek() == ')' && !test && !test2)
  35. {
  36. System.out.println("Najdeni se dupli zagradi");
  37. fin = true;
  38. break;
  39. }
  40.  
  41.  
  42. }
  43. if(!fin)
  44. System.out.println('/');
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement