当前位置:网站首页>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;
}
}
结果:
边栏推荐
- 软件测试基本流程有哪些?北京专业第三方软件检测机构安利
- Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
- Daily sql-employee bonus filtering and answer rate ranking first
- Unity程序员如何提升自己的能力
- Pico neo3在Unity中的交互操作
- JD.com product details API call example explanation
- Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
- Unity底层是如何处理C#的
- Waldom Electronics宣布成立顾问委员会
- 微信小程序功能上新(2022.06.01~2022.08.04)
猜你喜欢
随机推荐
Daily sql-statistics of the number of professionals (including the number of professionals is 0)
Trill keyword search goods - API
Pinduoduo api interface application example
daily sql - user retention rate for two days
ssh服务攻防与加固
Amazon Get AMAZON Product Details API Return Value Description
Internet phone software or consolidation of attack must be "free" calls security clearance
How to choose professional, safe and high-performance remote control software
go-grpc TSL认证 解决 transport: authentication handshake failed: x509 certificate relies on ... ...
easyrecovery15数据恢复软件收费吗?功能强大吗?
国密规范 SM2 SM3 SM4
【Pytorch】nn.PixelShuffle
第一个C函数:如何实现板级初始化?
Daily sql--statistics the total salary of employees in the past three months (excluding the latest month)
linux 安装mysql服务报错
Attitude solution - gyroscope + Euler method
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?
When MySQL uses GROUP BY to group the query, the SELECT query field contains non-grouping fields
DDR4内存条电路设计
Waldom Electronics宣布成立顾问委员会









