69,322
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
int main()
{
#if 1
char buf[100];
int num, cnt;
int i, j;
scanf("%d", &num);
while (getchar() != '\n')
;
for (i = 0; i < num; i++) {
fgets(buf, sizeof(buf), stdin);
cnt = 0;
for (j = 0; buf[j] != '\n' && buf[j]; j++) {
if (buf[j] == 'P' && cnt == 0)
cnt++;
if (buf[j] == 'A' && cnt == 1)
cnt++;
if (buf[j] == 'T' && cnt == 2)
break;
}
if (cnt >= 2)
printf("YES\n");
else
printf("NO\n");
}
#else
char c;
int num;
scanf("%d", &num);
while(getchar() != '\n')
; //来清除scanf缓存中的垃圾数据
int i=0;//count表示A分别在几个位置 的数量
char pri[num][3];
for(i=0;i<num;i++)
{
int pos=0,count[3]={0,0,0};//,count[3]={0,0,0}不能放上面
while((c=getchar())!='\n'){
if(c=='A') count[pos]++;
else if(c=='P'&&pos==0) pos=1;
else if(c=='T'&&pos==1) pos=2;
else break;
}
if(c=='\n'&&pos==2&&count[1]&&count[2]==count[1]*count[0]){
strcpy(pri[i],"YES");
}
else {
strcpy(pri[i],"NO");
}
if(c!='\n')
while(getchar()!='\n'); //来清除getchar缓存中的垃圾数据
}
for(int j=0;j<num;j++){
printf("%s\n",pri[j]);
}
#endif
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char c;
int num;
scanf("%d", &num);
while(getchar() != '\n');
int i=0;
char pri[11][4];//char pri[num][3];这个数组设置错误导致
for(i=0;i<num;i++)
{
int pos=0,count[3]={0};//count[3]={0,0,0};//,count[3]={0,0,0}不能放上面
while((c=getchar())!='\n'){
if(c=='A') count[pos]++;
else if(c=='P'&&pos==0) pos=1;
else if(c=='T'&&pos==1) pos=2;
else break;
}
if(c=='\n'&&pos==2&&count[1]&&count[2]==count[1]*count[0]){
strcpy(pri[i],"YES");
}
else {
strcpy(pri[i],"NO");
}
if(c!='\n')
while(getchar()!='\n');
}
for(int j=0;j<num;j++){
printf("%s\n",pri[j]);
}
return 0;
}
//8
//PAT
//PAAT
//AAPATAA
//AAPAATAAAA
//xPATx
//PT
//Whatever
//APAAATAA
//YES
//YES
//YES
//YES
//NO
//NO
//NO
//NO
//请按任意键继续. . .