Guest User

Untitled

a guest
Oct 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Stack;
  2. public class Parantes {
  3. Stack<Character> stack = new Stack<Character>();
  4. int tal;
  5. String kod;{
  6.  
  7.  
  8. // Iterate over the characters in the forward direction
  9. for (int j = 0; j < tal; j++){
  10. for (int i = 0; i < kod.length();) {
  11. if (kod.charAt(i) == '(' || kod.charAt(i) == '[' || kod.charAt(i) == '{'){
  12. stack.push(kod.charAt(i));
  13. }
  14. else if (kod.charAt(i) == ')' || kod.charAt(i) == ']' || kod.charAt(i) == '}'){
  15. if (stack.peek() == '(' && kod.charAt(i) == ')'){
  16. stack.pop();
  17. }
  18. else if (stack.peek() == '{' && kod.charAt(i) == '}'){
  19. stack.pop();
  20. }
  21. else if (stack.peek() == '[' && kod.charAt(i) == ']'){
  22. stack.pop();
  23. }
  24. else{
  25. System.out.println("No");
  26. break;
  27. }
  28. }
  29. System.out.println("Yes");
  30. }
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment