小结:这道题目的题意真的有些迷,看完答案,勉强接受了答案的说法,但是复习了二维字符组以及fgets的用法,收获还是不小的。
#include<cstdio>
#include<cstring>
int main()
{
int n;
scanf("%d", &n);
getchar();//用fgets的话,这里不用getchar会导致第一个fgets只吸收换行符
char str[15][110];
for (int i = 0; i < n; i++)
{
fgets(str[i], 110, stdin);
if (str[i][strlen(str[i]) - 1] == '\n') str[i][strlen(str[i]) - 1] = '\0';//以后还是养成写完fget加这一句的习惯比较好,要不然strlen会很不好用
//scanf("%s", str[i]);
}
/*for (int i = 0; i < n; i++)
{
printf("%s\n", str[i]);
}*/
int p, t;
for(int i=0;i<n;i++)
{
int countp = 0, countt = 0;
int other = 0;
int len = strlen(str[i]);
for (int j = 0; j < len; j++)
{
if (str[i][j] == 'P')
{
p = j;
countp++;
}
else if (str[i][j] == 'T')
{
t = j;
countt++;
}
else if (str[i][j] != 'A') other++;
}
if (countp != 1 || countt != 1 || other != 0 || t - p <= 1)
{
printf("NO\n");
continue;
}
int x, y, z;
x = p;
y = t - p - 1;
z = len-t-1;
//printf("%d %d %d\n", x, y, z);
if (z - x * (y - 1) == x) printf("YES\n");
else printf("NO\n");
}
return 0;
}