1003. 我要通过!
来源:互联网 发布:js 折叠 展开 编辑:程序博客网 时间:2024/06/04 22:50
1003. 我要通过!(20)
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于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 <stdio.h>#include <string.h>int main()
{
char c[100];
int i,j,n;
int count_P,count_A,count_T,pos_P,pos_T;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
gets(c);
count_P = 0;
count_A = 0;
count_T = 0;
pos_P = 0;
pos_T = 0;
for(j=0;j<strlen(c);j++)
{
if(c[j]=='P')
{
count_P++;
pos_P = j;
}
if(c[j]=='A')
count_A++;
if(c[j]=='T')
{
count_T++;
pos_T = j;
}
}
if(count_P+count_A+count_T != strlen(c) || pos_T-pos_P<=1 || count_P>1 || count_T>1 || pos_P*(pos_T-pos_P-1)!=strlen(c)-pos_T-1)
printf("NO\n");
else
printf("YES\n");
}
}
{
char c[100];
int i,j,n;
int count_P,count_A,count_T,pos_P,pos_T;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
gets(c);
count_P = 0;
count_A = 0;
count_T = 0;
pos_P = 0;
pos_T = 0;
for(j=0;j<strlen(c);j++)
{
if(c[j]=='P')
{
count_P++;
pos_P = j;
}
if(c[j]=='A')
count_A++;
if(c[j]=='T')
{
count_T++;
pos_T = j;
}
}
if(count_P+count_A+count_T != strlen(c) || pos_T-pos_P<=1 || count_P>1 || count_T>1 || pos_P*(pos_T-pos_P-1)!=strlen(c)-pos_T-1)
printf("NO\n");
else
printf("YES\n");
}
}
阅读全文
0 0
- 1003. 我要通过!
- 1003. 我要通过
- 1003. 我要通过!
- 1003. 我要通过!
- 1003.我要通过
- 1003. 我要通过!
- 1003. 我要通过
- 1003. 我要通过!
- 1003. 我要通过!
- 1003.我要通过
- 1003. 我要通过!
- 1003.我要通过
- 1003. 我要通过!
- 1003. 我要通过!
- 1003. 我要通过!
- 1003.我要通过!
- 1003.我要通过
- 1003. 我要通过
- 1061. 判断题
- 1056. 组合数的和
- 【算法题】按单词逆序
- Android中的属性,是怎么应用到控件上的(三)
- poj 1611 The Suspects
- 1003. 我要通过!
- poj3744 概率dp + 矩阵快速幂
- 使用MySQL Workbench远程连接Ubuntu MySQL
- Windows下GitHub的使用
- JAVA 复习总结(三)
- 深度神经网络结构以及Pre-Training的理解
- Ruby中include / extend / prepend的区别
- SIFT算法详解(二)
- 1031. 查验身份证