PAT答案(我要通过)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37568521/article/details/80135581

题目链接

https://www.patest.cn/contests/pat-b-practise/1003

代码

#include<iostream>
#include<string>
#include<queue>
using namespace std;

int main() {
    string s1;
    queue<int> q;
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int pNum = 0, Tnum = 0, Anum = 0, pindex = -1, tindex = -1, flag = 0;
        cin >> s1;
        for(int j=0; j<s1.size(); j++) {
            if(s1[j] == 'P') {
                pNum++;
                pindex = j;
                if(pNum > 1) { flag = 1; break;}
            } else if(s1[j] == 'A') {Anum++;}
            else if(s1[j] == 'T') {
                Tnum++;
                tindex = j;
                if(Tnum > 1) { flag = 1; break;}
            } else { flag = 1; break;}
        }
        if((s1.size() - tindex - 1) - (tindex - pindex - 2) * pindex != pindex || (tindex - pindex < 2)) flag = 1;
        if(flag || !Anum) q.push(0);
        else q.push(1);
    }
    while(!q.empty()) {
        if(q.front() == 0) cout << "NO" << endl;
        else cout << "YES" << endl;
        q.pop();
    }
    return 0;
}
展开阅读全文

没有更多推荐了,返回首页