PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
2018-04-12 16:34
393 查看
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 组成的字符串。
现在就请你为PAT写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。
输入格式: 每个测试输入包含1个测试用例。第1行给出一个自然数n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过100,且不包含空格。
输出格式:每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出YES,否则输出NO。
输入样例:
8 PAT PAAT AAPATAA AAPAATAAAA xPATx PT Whatever APAAATAA输出样例:
YES YES YES YES NO NO NO NO
#include<stdio.h> #include<string.h> int main() { int n; scanf("%d\n",&n); int h; for(h=0;h<n;h++) { char a[200]; gets(a); int i; int l=0,j=0,k=0; int flag=0,x=0; for(i=0;i<strlen(a);i++) { if(a[i]=='P'||a[i]=='A'||a[i]=='T') { if(a[i]=='A'&&flag==0) l++; if(a[i]=='P') flag=1; if(a[i]=='T') flag=2; if(a[i]=='A'&&flag==1) j++; if(a[i]=='A'&&flag==2) k++; } else { x=1; } } if(l*j==k&&x==0&&j!=0&&flag==2) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- 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乙级真题及训练集 PAT (Basic Level) Practise (中文)1003. 我要通过!
- PAT (Basic Level) Practise (中文) 1003.我要通过
- PAT (Basic Level) Practise (中文) 1049. 数列的片段和(20)
- PAT (Basic Level) Practise (中文)1042. 字符统计(20) C语言
- PAT (Basic Level) Practise (中文) 1007素数对猜想 (20)
- PAT (Basic Level) Practise (中文) 1009说反话 (20)
- PAT (Basic Level) Practise (中文)- 1018. 锤子剪刀布 (20)
- PAT (Basic Level) Practise (中文)- 1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1032. 挖掘机技术哪家强(20)
- PAT (Basic Level) Practise (中文)1049. 数列的片段和(20)
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20) C语言
- PAT (Basic Level) Practise (中文) 1042. 字符统计(20)