Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package AhmedAly;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Cafeteria {
  6. public static void main (String args[])
  7. {
  8. Scanner cs = new Scanner (System.in);
  9.  
  10. int t = cs.nextInt();
  11. int count = 0;
  12. for (int i = 0; i < t; i++)
  13. { StringBuilder str =new StringBuilder(cs.next());
  14. for (int j = 0; j < str.length(); j++)
  15. {
  16. if(str.charAt((int)j) >= 97)
  17. // if (Character.isLowerCase (str.charAt(j)))
  18.  
  19. {
  20.  
  21. if(str.charAt(j) == 'a')
  22. {
  23. String res =str.substring(0, j);
  24. if(res.contains("A"))
  25. {
  26. str.deleteCharAt(j);
  27. str.deleteCharAt(str.indexOf("A"));
  28. j=j-2;
  29. }
  30. }
  31. else
  32. if(str.charAt(j) == 'b')
  33. {
  34. String res1 =str.substring(0, j);
  35. if(res1.contains("B"))
  36. {
  37. str.deleteCharAt(j);
  38. str.deleteCharAt(str.indexOf("B"));
  39. j=j-2;
  40. }
  41. }
  42. else
  43. if(str.charAt(j) == 'c')
  44. {
  45. String res2 =str.substring(0, j);
  46. if(res2.contains("C"))
  47. {
  48. str.deleteCharAt(j);
  49. str.deleteCharAt(str.indexOf("C"));
  50. j=j-2;
  51. }
  52. }
  53. }
  54. }
  55.  
  56. if(str.length()== 0)
  57. {
  58. System.out.println("YES");
  59. }
  60. else
  61. {
  62. System.out.println("NO");
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement