PAT(Basic Level)1003 我要通过!
2017-11-25 17:07
337 查看
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 NONO
本题主要问题是读懂题目,题目总的意思是:必须有一个P和T,且P、T之间至少有一个A,另外,在P前的A的个数乘于P、T之间A的个数等于T后A的个数。
#include <stdio.h>
#include <string.h>
int main()
{
int i, n=0, size;
char ch[101];
scanf("%d", &n);
while(n--){
int p=0, a=0, t=0, sp=0, st=0, flag=1; //PAT的个数 ,sp:P的下标,st:T的下标,flag保证不能有其他字符
scanf("%s", ch);
size=strlen(ch);
for(i=0;i<size;i++){
switch(ch[i]){
case 'P':p++;sp=i;break;
case 'A':a++;break;
case 'T':t++;st=i;break;
default:flag=0;
}
}
if(p==1&&t==1&&a>0&&st-sp>0&&flag==1){
int a, b, c;
a=sp;
b=st-sp-1;
c=size-st-1;
if(a*b==c)
printf("YES\n");
else
printf("NO\n");
}
else
printf("NO\n");
}
return 0;
}
相关文章推荐
- PAT(Basic Level)_1003_我要通过!
- PAT BASIC LEVEL 1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT Basic Level 1003:我要通过!
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1003. 我要通过!
- PAT (Basic Level) Practise (中文) 1003.我要通过!(20)
- Pat(Basic Level)Practice--1003(我要通过)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT 1003 我要通过! (Basic Level)
- PAT (Basic Level)1003.我要通过
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)- 1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文) 1003.我要通过
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise 1003. 我要通过!
- PAT Basic Level 1003. 我要通过!(20)
- PAT(basic level) 1003 我要通过
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20) C语言
- 浙大 pat Basic Level 1003
- pat(basic level) 1003