1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <algorithm> 5 using namespace std; 6 //题目贼恶心,竟然没有说出A存在的规律!!!!! 7 //首先,必须要有PAT存在,且不能有其他字符 8 //其次P与T中间A的个数乘以P之前的个数==T之后的A的个数!!!!!!!!! 9 int main() { 10 int n; 11 cin >> n; 12 vector<string> v(n, "YES"); 13 for (int i = 0; i < n; ++i) { 14 string s; 15 cin >> s; 16 int p = s.find(‘P‘); 17 int t = s.find(‘T‘); 18 int a = count(s.begin(), s.end(), ‘A‘);//统计A的字符 19 if (p == -1 || t == -1 || (t - 1) <= p || a != (s.size() - 2)) { 20 //P或T或T不在P后面或存在其他字母则输出false 21 v[i] = "NO"; 22 continue; 23 } 24 else if (p*(t - p - 1) != (s.size() - 1 - t)) { 25 v[i] = "NO"; 26 continue; 27 } 28 } 29 for (int i = 0; i < n; ++i) { 30 cout << v[i] << endl; 31 } 32 33 return 0; 34 }
原文地址:https://www.cnblogs.com/zzw1024/p/10556092.html
时间: 2024-10-07 00:56:56