当前位置:网站首页>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;
}
}
结果:
边栏推荐
- LeetCode刷题系列 -- 46. 全排列
- Unity开发者必备的C#脚本技巧
- 【深度学习】什么是互信息最大化?
- DDR4内存条电路设计
- js根据当天获取前几天的日期
- 《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台
- Daily sql: request for friend application pass rate
- SQL滑动窗口
- How do you optimize the performance of your Unity project?
- Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
猜你喜欢
随机推荐
Daily sql: request for friend application pass rate
2022-08-09 Group 4 Self-cultivation class study notes (every day)
一种用于EEG超扫描研究的分析流程
Unity程序员如何提升自己的能力
机器学习总结(二)
深度监督(中继监督)
golang fork 进程的三种方式
2022年中国软饮料市场洞察
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
Pico neo3 Unity打包设置
CIKM 2022 AnalytiCup Competition: 联邦异质任务学习
囍楽云任务源码
Pico neo3在Unity中的交互操作
Daily sql-statistics of the number of professionals (including the number of professionals is 0)
结合均线分析k线图的基本知识
JD.com product details API call example explanation
Unity开发者必备的C#脚本技巧
Shell:三剑客之awk
为什么C#中对MySQL不支持中文查询
详述MIMIC 的ICU患者检测时间信息表(十六)