Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AhmedAly;
- import java.util.Scanner;
- public class Cafeteria {
- public static void main (String args[])
- {
- Scanner cs = new Scanner (System.in);
- int t = cs.nextInt();
- int count = 0;
- for (int i = 0; i < t; i++)
- { StringBuilder str =new StringBuilder(cs.next());
- for (int j = 0; j < str.length(); j++)
- {
- if(str.charAt((int)j) >= 97)
- // if (Character.isLowerCase (str.charAt(j)))
- {
- if(str.charAt(j) == 'a')
- {
- String res =str.substring(0, j);
- if(res.contains("A"))
- {
- str.deleteCharAt(j);
- str.deleteCharAt(str.indexOf("A"));
- j=j-2;
- }
- }
- else
- if(str.charAt(j) == 'b')
- {
- String res1 =str.substring(0, j);
- if(res1.contains("B"))
- {
- str.deleteCharAt(j);
- str.deleteCharAt(str.indexOf("B"));
- j=j-2;
- }
- }
- else
- if(str.charAt(j) == 'c')
- {
- String res2 =str.substring(0, j);
- if(res2.contains("C"))
- {
- str.deleteCharAt(j);
- str.deleteCharAt(str.indexOf("C"));
- j=j-2;
- }
- }
- }
- }
- if(str.length()== 0)
- {
- System.out.println("YES");
- }
- else
- {
- System.out.println("NO");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement