PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
来源:互联网 发布:购物群软件 编辑:程序博客网 时间:2024/06/05 09:01
1003. 我要通过!(20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。
得到“答案正确”的条件是:
1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a, b, c 均或者是空字符串,或者是仅由字母 A 组成的字符串。
输入格式: 每个测试输入包含1个测试用例。第1行给出一个自然数n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过100,且不包含空格。
输出格式:每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出YES,否则输出NO。
输入样例:8PATPAATAAPATAAAAPAATAAAAxPATxPTWhateverAPAAATAA输出样例:
YESYESYESYESNONONONO
#include <cstdio>#include <cstring>const int maxn=105;char s[maxn];int main(){ int T; scanf("%d",&T); while(T--){ scanf("%s",s); int n=strlen(s); int num_p=0,num_t=0,other=0; int loc_p=-1,loc_t=-1; for(int i=0;i<n;i++){ if(s[i]=='P'){ num_p++; loc_p=i; } else if(s[i]=='T'){ num_t++; loc_t=i; } else if(s[i]!='A') other++; } if(num_p!=1||num_t!=1||other!=0||loc_t-loc_p<=1){ puts("NO"); continue; } int x=loc_p,y=loc_t-loc_p-1,z=n-loc_t-1; if(z-x*(y-1)==x) puts("YES"); else puts("NO"); } return 0;}
阅读全文
0 0
- PAT (Basic Level) Practise (中文) 1003.我要通过
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20) C语言
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文) 1003.我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)—— 1003. 我要通过!
- PAT (Basic Level) Practise 1003. 我要通过!
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- Linux CentOS 7 安装字体库 & 中文字体
- C++线段树初步(下)
- Redis 在Centos7下配置开机自启动
- 补齐函数求数根
- SVN问题-Failed to load JavaHL Library
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- 上传下载
- while,do while,for循环总结
- CSS盒子模型
- angular1项目中bower的使用
- 2017/10/29学习心得
- C和指针之用拉托斯特尼筛方法(Eratosthenes)查找区间质素个数
- debian安装 MariaDB,没有提示输入 root 的密码?
- 为何spring cloud 应该使用 Euraka server 而不是 Zookeeper