admin 管理员组

文章数量: 887007

PAT(乙级) 1003.我要通过

题目:点击打开链接

分析:本题目虽然是个乙级题,但可以说题意真的是十分难懂,明明每个字都看得懂,题意却是一坨屎。总的来说,那三个拗口的原则的意思就是必然有一个P和T,而A的数量应保证P之前与P和T中间的数量乘积等于T之后的A的数量(当然只存在P,A,T三种字母)。

代码:

#include<stdio.h>
#include<string.h>
int main()
{char s[110];int pos_p,pos_t,count_p,count_a,count_t,n;scanf("%d\n",&n);while(n--){pos_p=pos_t=count_p=count_a=count_t=0;gets(s);for(int i=0;i<strlen(s);i++){if(s[i] == 'P'){count_p++;pos_p = i;}else if(s[i] == 'A'){count_a++;}else if(s[i] == 'T'){count_t++;pos_t = i;}}if(count_p+count_a+count_t<strlen(s)|| count_p>1 || count_t>1 || pos_p*(pos_t-pos_p-1)!=strlen(s)-pos_t-1 || pos_t-pos_p<=1)printf("NO\n");elseprintf("YES\n");}}
大概就是这样,事实告诉我们,还是要学好语文,弄懂题意才行!

本文标签: PAT(乙级) 1003我要通过