PAT|PAT 1003 我要通过! (20 分)
#include
#include
using namespace std;
int pd(string s) {
string ks = "PAT";
for (int i = 0;
i < s.length();
i++)//确保只有PAT三种字符
if (ks.find(s[i]) == string::npos)//找不到
return 0;
int lc = s.find('P'),
mc = s.find('T') - s.find('P') - 1,
rc = s.length() - s.find('T') - 1;
if (lc*mc == rc && (rc || mc || lc))//满足条件
return 1;
return 0;
}
int main()
{
int n;
cin >> n;
string str;
while (n--) {
cin >> str;
if (pd(str))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
//P左边A的个数*中间A的个数==T右边A的个数(但要保证只有存在A)
//注意:要保证只有PAT三种字符,并且三种字符都要有 ,满足条件即可。
【PAT|PAT 1003 我要通过! (20 分)】GitHub
推荐阅读
- 我要做大厨
- 我要我们在一起(二)
- 五年后,我要成为独立自强自信的女性
- Python(pathlib模块)
- Realm
- 王羲之之才子
- 第二十九章
- 调侃语录(二)
- 颠覆世界|下弦集|为了你们,我要走遍全世界_笔若的诗?
- Vol.3「贫穷会遗传吗(」-171003)