1003 我要通过! (20 分)
仅供参考
#include<stdio.h>
#include<string.h>
int main(){
int i,n,m;
int p,a,t,loc_p,loc_t,other;
int pre,in,last;
char b[100];
scanf("%d",&n);
while(n){
other=1;
p=0;
a=0;
t=0;
loc_p=0;
loc_t=0;
scanf("%s",b);
m=strlen(b);
for(i=0;i<m;i++){
switch(b[i]){
case 'P':p++;loc_p=i;break;
case 'A':a++;break;
case 'T':t++;loc_t=i;break;
default:other=0;break;
}
}
pre=loc_p;
in=loc_t-loc_p-1;
last=m-loc_t-1;
if((p==1)&&(t==1)&&(other==1)&&a&&(loc_p<loc_t)&&(pre*in==last))
printf("YES\n");
else
printf("NO\n");
n--;
}
return 0;
}