当前位置:网站首页>1003 我要通过 (20 分)
1003 我要通过 (20 分)
2022-08-11 06:45:00 【呆比特】
1003 我要通过! (20 分)
题目要求:

代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//輸入
int n = scan.nextInt();
scan.nextLine();
//逐个判断
for (int i = 0; i < n; i++) {
String str = scan.nextLine();
if (check(str)){
System.out.println("YES");
} else{
System.out.println("NO");
}
}
}
private static boolean check(String str){
boolean flag = true;
//判断字符串中有且只由PAT三个字符组成
String s = str.trim().replaceAll("P", "").replaceAll("A", "").replaceAll("T", "");
if (!"".equals(s)){
flag = false;
}
//判断PT唯一
if (!(str.indexOf("P") == str.lastIndexOf("P") && str.indexOf("T") == str.lastIndexOf("T"))){
flag = false;
}
//判断A的个数
int left = str.indexOf("P");
int mid = str.indexOf("T") - left - 1;
int right = str.endsWith("A") ? str.lastIndexOf("A") - str.indexOf("T") : 0;
if (!(right == left * mid)){
flag = false;
}
//判断P在T的前面
if (str.indexOf("T") - str.indexOf("P") - 1 <= 0){
flag = false;
}
return flag;
}
}
结果:
边栏推荐
猜你喜欢

buu—Re(5)

How to choose professional, safe and high-performance remote control software

Pico neo3 Unity打包设置

《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台

结合均线分析k线图的基本知识

详述MIMIC 的ICU患者检测时间信息表(十六)

【latex异常和错误】Missing $ inserted.<inserted text>You can‘t use \spacefactor in math mode.输出文本要注意特殊字符的转义

Douyin API interface

prometheus学习5altermanager

【@网络工程师:用好这6款工具,让你的工作效率大翻倍!】
随机推荐
【Pytorch】nn.PixelShuffle
LeetCode brushing series -- 46. Full arrangement
结合均线分析k线图的基本知识
Depth (relay supervision)
求职简历这样写,轻松搞定面试官
TF中的条件语句;where()
C语言每日一练——Day02:求最小公倍数(3种方法)
tf中自减操作;tf.assign_sub()
你是如何做好Unity项目性能优化的
6月各手机银行活跃用户较快增长,创半年新高
Activity的四种启动模式
Redis + lua implements distributed interface current limiting implementation scheme
【软件测试】(北京)字节跳动科技有限公司终面HR面试题
技术分享 | 实战演练接口自动化如何处理 Form 请求?
exness:黄金1800关口遇阻,静待美国CPI出炉
go-grpc TSL认证 解决 transport: authentication handshake failed: x509 certificate relies on ... ...
Production and optimization of Unity game leaderboards
CIKM 2022 AnalytiCup Competition: 联邦异质任务学习
Multiscale communication in cortical-cortical networks
如何选择专业、安全、高性能的远程控制软件