当前位置:网站首页>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;
}
}
结果:
边栏推荐
- ssh服务攻防与加固
- Production and optimization of Unity game leaderboards
- unable to extend table xxx by 1024 in tablespace xxxx
- 为什么我使用C#操作MySQL进行中文查询失败
- MindManager2022全新正式免费思维导图更新
- 一张图了解JVM八大原子操作
- Pinduoduo API interface
- Strongly recommend an easy-to-use API interface
- Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
- 常见激活函数及其导数
猜你喜欢
Serverless + domain name can also build a personal blog? Really, and soon
恒源云-Pycharm远程训练避坑指南
ROS 话题通信理论模型
How to choose professional, safe and high-performance remote control software
TF通过feature与label生成(特征,标签)集合,tf.data.Dataset.from_tensor_slices
Discourse's Close Topic and Reopen Topic
进制转换间的那点事
PIXHAWK飞控使用RTK
TF中的四则运算
详述 MIMIC护理人员信息表(十五)
随机推荐
tf.cast(), reduce_min(), reduce_max()
Pico neo3 Unity打包设置
Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
动态代理学习
Unity3D learning route?
Edge provides label grouping functionality
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
SQL sliding window
How do you optimize the performance of your Unity project?
Pinduoduo API interface
计算YUV文件的PSNR与SSIM
prometheus学习4Grafana监控mysql&blackbox了解
国密规范 SM2 SM3 SM4
Redis source code-String: Redis String command, Redis String storage principle, three encoding types of Redis string, Redis String SDS source code analysis, Redis String application scenarios
Service的两种状态形式
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
【推荐系统】:协同过滤和基于内容过滤概述
【Pytorch】nn.PixelShuffle
囍楽云任务源码
线程交替输出(你能想出几种方法)