Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int N = in.nextInt();
- in.nextLine();
- for (int i = 0; i < N; i++) {
- String mask = in.nextLine();
- if (mask.equals("")) {
- System.out.println("yes");
- continue;
- }
- String[] symbols = mask.split("");
- boolean check = true;
- int count = 0;
- int wild = 0;
- for (int j = 0; j < symbols.length; j++) {
- if (symbols[j].equals("*")){
- wild++;
- continue;
- }
- if (symbols[j].equals("(")){
- count++;
- continue;
- }
- if (symbols[j].equals(")")) {
- count--;
- if (count < 0) {
- if (wild > 0) {
- wild--;
- count++;
- continue;
- } else {
- check = false;
- break;
- }
- }
- }
- }
- if (count - wild > 0) {
- check = false;
- }
- if (check) {
- System.out.println("yes");
- } else {
- System.out.println("no");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement