1003 我要通过!(20 分)

#include
#include
#include
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    getchar();
    while (n--)
    {
        string s;
        getline(cin, s);
        bool f = true;
        int p=0, t=0, pnum=0, tnum=0, x, y, z;
        for (int i = 0; i < s.length(); i++)
        {
            if (s[i] == 'P')p = i, pnum++;
            else if (s[i] == 'T')t = i, tnum++;
            else if (s[i] == 'A')continue;
            else f = false;
        }
        x = p - 0, y = t - p - 1, z = s.length() - t - 1;
        if (f == false || pnum != 1 || tnum != 1 || y == 0)
        {
            printf("NO\n");
            continue;
        }
        if (x == (z - (y - 1)*x))printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

你可能感兴趣的:(1003 我要通过!(20 分))