分析:这道题难度不在于如何求解,而在于如何确切的理解题意,一开始我直接强解导致有两个测试点不过,之后经过仔细研究分析,终于解决了这两个点。
题意:1.输入一个小于十的数;
2.每个字符串不超过100个字符且无空格;
3.每行一个输出。
算法:1.出现PAT之外的字符均输出NO;
2.Location T - Location P -1 < 2 时输出NO;
3.(Location T - Location P - 1)* Location P = 字符串长度 -1 - Location T 。
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char test[10][101];
int num,result[11];
cin >> num;
if (num < 10)
{
for (int i = 0; i < num; i++) {
cin >> test[i];
}
for (int i = 0; i < num; i++) {
int a, b, c, x = 0, y = 0, z = 0;
a = strlen(test[i]);
for (int j = 0; j < a; j++) {
if (test[i][j] == 'A')
;
else if (test[i][j] == 'P') {
b = j;
if (x == 1) {
z = 1;
break;
}
x = 1;
}
else if (test[i][j] == 'T') {
c = j;
if (y == 1) {
z = 1;
break;
}
y = 1;
}
else {
z = 1;
break;
}
}
if (z == 1) {
result[i] = 0;
}
else
{
if (c - b <= 1)
result[i] = 0;
else {
if ((c - b -1 )*b == a - c - 1) {
result[i] = 1;
}
else
result[i] = 0;
}
}
}
char yes[1][4] = { "YES" }, no[1][4] = { "NO" };
for (int i = 0; i < num; i++) {
if (result[i] == 0)
cout << no[0] << endl;
else if (result[i] == 1)
cout << yes[0] << endl;
}
}
return 0;
}