//→_→转载请注明出处,谢谢 http://blog.youkuaiyun.com/woot_the_woot
//题目大意是判断整个字符串是不是这样的形式---》
嗯就是右边这样---》xPyTz 其中x y z都是只包含A的字符串或者空字符串 并且y不能为空串 x中A的个数*y中A的个数=z中A的个数【大概我这样能把题意说清楚】
于是愉快的按照这个模拟就好?
//发现自己说话简直啰嗦
// 自己的代码事后自己已经看不懂了= =所以还是找一份别人的代码存着好了
//
#include <string>
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
string s;
cin >> s;
size_t p = s.find_first_not_of("A");
if ((p == string::npos) || (s[p] != 'P'))
{
cout << "NO" << endl;
continue;
}
size_t t = s.find_first_not_of("A", p + 1);
if ((t == string::npos) || (t == p + 1) || (s[t] != 'T'))
{
cout << "NO" << endl;
continue;
}
size_t n = s.find_first_not_of("A", t + 1);
if (n != string::npos)
{
cout << "NO" << endl;
continue;
}
if ((s.length() - t - 1) == p * (t - p - 1))
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
return 0;
}