首页 > 其他 > 详细

PAT1003

时间:2018-03-24 11:10:06      阅读:214      评论:0      收藏:0      [点我收藏+]

代码如下:

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");
        }
    }
}

 

PAT1003

原文:https://www.cnblogs.com/LoganChen/p/8637761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!