当前位置:网站首页>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;
}
}
结果:
边栏推荐
- 2022-08-10 Group 4 Self-cultivation class study notes (every day)
- buu—Re(5)
- Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
- 6月各手机银行活跃用户较快增长,创半年新高
- 软件测试基本流程有哪些?北京专业第三方软件检测机构安利
- Item 2 - Annual Income Judgment
- STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
- SQL sliding window
- TF中的条件语句;where()
- 你是如何做好Unity项目性能优化的
猜你喜欢
随机推荐
伦敦银规则有哪些?
语音信号处理:预处理【预加重、分帧、加窗】
1002 Write the number (20 points)
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
接口测试的基础流程和用例设计方法你知道吗?
关于Android Service服务的面试题
1056 组合数的和 (15 分)
深度监督(中继监督)
Redis源码:Redis源码怎么查看、Redis源码查看顺序、Redis外部数据结构到Redis内部数据结构查看源码顺序
年薪40W测试工程师成长之路,你在哪个阶段?
Unity底层是如何处理C#的
囍楽云任务源码
Pico neo3 Unity打包设置
【深度学习】什么是互信息最大化?
ssh服务攻防与加固
那些事情是用Unity开发项目应该一开始规划好的?如何避免后期酿成巨坑?
STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
4.1-支持向量机
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
软件测试基本流程有哪些?北京专业第三方软件检测机构安利