标签:iterator mes ios string algo using begin cin str
1 #include<iostream> 2 #include<string> 3 #include<vector> 4 #include<algorithm> 5 #include<iterator> 6 #include<windows.h> 7 8 using namespace std; 9 10 int main() 11 { 12 int n; 13 int cnt = 0; 14 string s; 15 cin >> n; 16 while (cnt != n) 17 { 18 int a = 0, b = 0, c = 0; 19 ++cnt; 20 cin >> s; 21 auto iter1 = find(s.begin(), s.end(), ‘P‘); 22 auto iter2 = find(s.begin(), s.end(), ‘T‘); 23 if (iter1 == s.end() || iter2 == s.end()) 24 { 25 cout << "NO" << endl; 26 continue; 27 } 28 auto iter = s.begin(); 29 for (; iter != iter1; ++iter) 30 { 31 if (*iter != ‘A‘) 32 break; 33 ++a; 34 } 35 if(iter != iter1) 36 { 37 cout << "NO" << endl; 38 continue; 39 } 40 for (++iter; iter != iter2; ++iter) 41 { 42 if (*iter != ‘A‘) 43 break; 44 ++b; 45 } 46 if (iter != iter2) 47 { 48 cout << "NO" << endl; 49 continue; 50 } 51 for (++iter; iter != s.end(); ++iter) 52 { 53 if (*iter != ‘A‘) 54 break; 55 ++c; 56 } 57 if (iter != s.end()) 58 { 59 cout << "NO" << endl; 60 continue; 61 } 62 if (b == 0 || a*b != c) 63 { 64 cout << "NO" << endl; 65 continue; 66 } 67 cout << "YES" << endl; 68 } 69 70 system("pause"); 71 return 0; 72 }
本题是一道数学问题(找规律),需满足‘P‘之前‘A‘的个数乘以‘P‘与‘T‘之间‘A‘的个数=‘T‘之后‘A‘的个数。注意‘P‘与‘T‘之间必须要有‘A‘。
标签:iterator mes ios string algo using begin cin str
原文地址:https://www.cnblogs.com/Huayra/p/12161852.html