Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. int N = in.nextInt();
  8. in.nextLine();
  9. for (int i = 0; i < N; i++) {
  10. String mask = in.nextLine();
  11. if (mask.equals("")) {
  12. System.out.println("yes");
  13. continue;
  14. }
  15. String[] symbols = mask.split("");
  16. boolean check = true;
  17. int count = 0;
  18. int wild = 0;
  19. for (int j = 0; j < symbols.length; j++) {
  20. if (symbols[j].equals("*")){
  21. wild++;
  22. continue;
  23. }
  24. if (symbols[j].equals("(")){
  25. count++;
  26. continue;
  27. }
  28. if (symbols[j].equals(")")) {
  29. count--;
  30. if (count < 0) {
  31. if (wild > 0) {
  32. wild--;
  33. count++;
  34. continue;
  35. } else {
  36. check = false;
  37. break;
  38. }
  39. }
  40. }
  41. }
  42. if (count - wild > 0) {
  43. check = false;
  44. }
  45. if (check) {
  46. System.out.println("yes");
  47. } else {
  48. System.out.println("no");
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement