当前位置:网站首页>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;
}
}
结果:
边栏推荐
- 数仓开发知识总结
- easyrecovery15数据恢复软件收费吗?功能强大吗?
- Redis + lua implements distributed interface current limiting implementation scheme
- Multiscale communication in cortical-cortical networks
- Daily sql: request for friend application pass rate
- 下一代 无线局域网--强健性
- Edge provides label grouping functionality
- 《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台
- 技术分享 | 实战演练接口自动化如何处理 Form 请求?
- Unity底层是如何处理C#的
猜你喜欢
SQL sliding window
Douyin API interface
buu—Re(5)
Edge 提供了标签分组功能
Attitude solution - gyroscope + Euler method
《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台
ROS 服务通信理论模型
【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法
When MySQL uses GROUP BY to group the query, the SELECT query field contains non-grouping fields
daily sql - query for managers and elections with at least 5 subordinates
随机推荐
下一代 无线局域网--强健性
Daily SQL - find each of the students school gpa minimum (window)
Edge provides label grouping functionality
MySQL使用GROUP BY 分组查询时,SELECT 查询字段包含非分组字段
Taobao API interface reference
ssh服务攻防与加固
【软件测试】(北京)字节跳动科技有限公司二面笔试题
How do you optimize the performance of your Unity project?
linux 安装mysql服务报错
进制转换间的那点事
Unity3D 学习路线?
EasyPlayer针对H.265视频不自动播放设置下,loading状态无法消失的解决办法
TF中的条件语句;where()
radix-4 FFT principle and C language code implementation
daily sql - user retention rate for two days
Discourse 的关闭主题(Close Topic )和重新开放主题
Edge 提供了标签分组功能
MySQL 版本升级心得
Coordinate system in navigation and positioning
maxwell concept