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"); } } }
心再坚强也不要独自飞翔
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步