当前位置:网站首页>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;
}
}
结果:
边栏推荐
猜你喜欢

【软件测试】(北京)字节跳动科技有限公司二面笔试题

1071 小赌怡情 (15 分)

1046 划拳 (15 分)

1002 Write the number (20 points)

Daily sql-statistics of the number of professionals (including the number of professionals is 0)

Redis source code: how to view the Redis source code, the order of viewing the Redis source code, the sequence of the source code from the external data structure of Redis to the internal data structu

常见激活函数及其导数

结合均线分析k线图的基本知识

语音信号处理:预处理【预加重、分帧、加窗】

1051 复数乘法 (15 分)
随机推荐
1036 跟奥巴马一起编程 (15 分)
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
TF中的条件语句;where()
jar服务导致cpu飙升问题-带解决方法
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
maxwell concept
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
详述MIMIC 的ICU患者检测时间信息表(十六)
Redis source code: how to view the Redis source code, the order of viewing the Redis source code, the sequence of the source code from the external data structure of Redis to the internal data structu
break pad源码编译--参考大佬博客的总结
求职简历这样写,轻松搞定面试官
梅科尔工作室——BP神经网络
Unity游戏排行榜的制作与优化
Serverless + domain name can also build a personal blog? Really, and soon
oracle19c不支持实时同步参数,请教一下大佬们有什么好的解决办法吗?
1071 小赌怡情 (15 分)
6月各手机银行活跃用户较快增长,创半年新高
接口测试的基础流程和用例设计方法你知道吗?
【Pytorch】nn.ReLU(inplace=True)
JVM学习——3——数据一致性