当前位置:网站首页>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;
}
}
结果:
边栏推荐
- 3GPP LTE/NR信道模型
- Pytorch模型转ONNX模型
- buu—Re(5)
- 【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法
- Douyin share password url API tool
- Daily sql-employee bonus filtering and answer rate ranking first
- SQL sliding window
- 《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台
- 公牛10-11德里克·罗斯最强赛季记录
- C语言每日一练——Day02:求最小公倍数(3种方法)
猜你喜欢
随机推荐
Trill keyword search goods - API
恒源云-Pycharm远程训练避坑指南
一张图了解JVM八大原子操作
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-seek the sum of successful investments in 2016
PIXHAWK飞控使用RTK
Taobao API interface reference
【sdx62】XBL设置共享内存变量,然后内核层获取变量实现
Activity的四种启动模式
Get Pinduoduo product information operation details
How Unity handles C# under the hood
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
prometheus学习4Grafana监控mysql&blackbox了解
Tidb二进制集群搭建
求职简历这样写,轻松搞定面试官
从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
技术分享 | 实战演练接口自动化如何处理 Form 请求?
Internet phone software or consolidation of attack must be "free" calls security clearance
STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
prometheus学习5altermanager