Advertisement
vov44k

51

Nov 27th, 2022
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) throws FileNotFoundException {
  6. //        Scanner scanner = new Scanner(System.in);
  7.         Scanner in = new Scanner(new File("input.txt"));
  8.         PrintWriter pw = new PrintWriter("output.txt");
  9.  
  10.  
  11.         Stack<Character> stack = new Stack<>();
  12.         String a = in.next();
  13.  
  14.         boolean flag = false;
  15.         for (int i = 0; i < a.length(); i++)
  16.             if (a.charAt(i) == '{' || a.charAt(i) == '(' || a.charAt(i) == '[') stack.push(a.charAt(i));
  17.             else if (stack.size() == 0) flag = true;
  18.             else if (stack.peek() == '{' && a.charAt(i) == '}' || stack.peek() == '(' && a.charAt(i) == ')' || stack.peek() == '[' && a.charAt(i) == ']')
  19.                 stack.pop();
  20.             else flag = true;
  21.  
  22.  
  23.         if (stack.size() != 0) flag = true;
  24.  
  25.         if (flag) {
  26.             pw.println("no");
  27.         } else {
  28.             pw.println("yes");
  29.         }
  30.  
  31.  
  32.         in.close();
  33.         pw.close();
  34.  
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement