PAT1003

代码如下:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();
        String[] StrArr = new String[num];
        for(int i = 0;i<num;i++){
            StrArr[i] = input.next();
        }
        for(int j = 0;j<num;j++){
            judge(StrArr[j]);
        }
    }
    
    public static void judge(String str){
        String pattern1 = "A*PA+TA*";
        String pattern2 = "PA+T";
        if(str.matches(pattern1)){
            if(str.matches(pattern2)){
                System.out.println("YES");
            }else{
                String temp[] = str.split("P|T");
                int aLength = temp[0].length();
                int bLength = temp[1].length();
                int cLentth = temp[2].length();
                if((cLentth-aLength)/aLength==(bLength-1)){
                    System.out.println("YES");
                }else{
                    System.out.println("NO");
                }
            }
        }else{
            System.out.println("NO");
        }
    }
}

 

posted @ 2018-03-24 10:29  alittlecomputer  阅读(121)  评论(0编辑  收藏  举报