当前位置:网站首页>1003 I want to pass (20 points)
1003 I want to pass (20 points)
2022-08-11 07:48:00 【dumb bit】
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;
//Determine if the string contains and only consists ofPAT三个字符组成
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;
}
}
结果:
边栏推荐
- 1096 大美数 (15 分)
- 机器学习总结(二)
- go-grpc TSL认证 解决 transport: authentication handshake failed: x509 certificate relies on ... ...
- 【LeetCode每日一题】——844.比较含退格的字符串
- There may be fields that cannot be serialized in the abnormal object of cdc and sqlserver. Is there anyone who can understand it? Help me to answer
- 为什么我使用C#操作MySQL进行中文查询失败
- What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?
- 易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
- 项目2-年收入判断
- Discourse's Close Topic and Reopen Topic
猜你喜欢
随机推荐
Edge 提供了标签分组功能
Unity3D 学习路线?
Redis source code-String: Redis String command, Redis String storage principle, three encoding types of Redis string, Redis String SDS source code analysis, Redis String application scenarios
1003 我要通过 (20 分)
ROS 话题通信理论模型
Unity程序员如何提升自己的能力
1071 小赌怡情 (15 分)
Pico neo3 Unity打包设置
博途PLC 1200/1500PLC ModbusTcp通信梯形图优化汇总(多服务器多从站轮询)
1096 大美数 (15 分)
unable to extend table xxx by 1024 in tablespace xxxx
C语言每日一练——Day02:求最小公倍数(3种方法)
How to choose professional, safe and high-performance remote control software
NFT 的价值从何而来
软件测试主要做什么工作,难不难?
js判断图片是否存在
LeetCode brushing series -- 46. Full arrangement
Redis测试
Discourse's Close Topic and Reopen Topic
囍楽云任务源码









