【Basic Level】
*1003 找出规律
#include <iostream>
#include <string>
using namespace std;
bool isPAT(string s0) {
int a = 0, b= 0;
int ca = 0, cb = 0;
for (int i = 0; i < s0.length(); i++)
{
if (s0[i] != 'P' && s0[i] != 'A' && s0[i] != 'T')
{
return false;
}
if (s0[i] == 'P')
{
a = i;
ca++;
}
if (s0[i] == 'T')
{
b = i;
cb++;
}
}
if (a * (b - a - 1) == (s0.length() - b -1) && b - a - 1 > 0 && ca == 1 && cb == 1)
{
return true;
}
else
{
return false;
}
}
int main()
{
int n=0;
string s;
cin >> n;
while (n--)
{
cin >> s;
if (isPAT(s))
{
if (n!=0)
cout << "YES" <<endl;
else
cout << "YES";
}
else
{
if (n!=0)
cout << "NO" <<endl;
else
cout <<"NO";
}
}
return 0;
}