- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- // 题目贼恶心, 竟然没有说出 A 存在的规律!!!!!
- // 首先, 必须要有 PAT 存在, 且不能有其他字符
- // 其次 P 与 T 中间 A 的个数乘以 P 之前的个数 ==T 之后的 A 的个数!!!!!!!!!
- int main() {
- int n;
- cin>> n;
- vector<string> v(n, "YES");
- for (int i = 0; i <n; ++i) {
- string s;
- cin>> s;
- int p = s.find('P');
- int t = s.find('T');
- int a = count(s.begin(), s.end(), 'A');// 统计 A 的字符
- if (p == -1 || t == -1 || (t - 1) <= p || a != (s.size() - 2)) {
- //P 或 T 或 T 不在 P 后面或存在其他字母则输出 false
- v[i] = "NO";
- continue;
- }
- else if (p*(t - p - 1) != (s.size() - 1 - t)) {
- v[i] = "NO";
- continue;
- }
- }
- for (int i = 0; i < n; ++i) {
- cout << v[i] << endl;
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2992175.html