Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Stack;
- public class Zagradi_ispitna {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String s = in.nextLine();
- Stack<Character> st = new Stack<Character>();
- boolean test = false;
- boolean test2 = false;
- boolean fin = false;
- for(int i=0; i<s.length(); i++)
- {
- st.push(s.charAt(i));
- if(test && st.peek()=='(')
- test2 = true;
- if(Character.isAlphabetic(st.peek()) || st.peek()=='+')
- {
- st.pop();
- test = true;
- continue;
- }
- if(st.peek()==')' && (test || test2))
- {
- st.pop();st.pop();
- if(!test)
- {
- test2 = false;
- }
- test = false;
- }
- else if(st.peek() == ')' && !test && !test2)
- {
- System.out.println("Najdeni se dupli zagradi");
- fin = true;
- break;
- }
- }
- if(!fin)
- System.out.println('/');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement