PTA 我要通过! (20分)

    科技2022-08-08  102

    每个人都有崩溃的时候,就看你的抗压能力到底有多强,如果你的抗压能力强,有办法可以支撑到你能面对并且解决这些困难的话,你就没有问题。                                                                          ----喻言

    “答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。

    得到“答案正确”的条件是:

    字符串中必须仅有 P、 A、 T这三种字符,不可以包含其它字符;任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a、 b、 c 均或者是空字符串,或者是仅由字母 A 组成的字符串。

    现在就请你为 PAT 写一个自动裁判程序,判定哪些字符串是可以获得“答案正确”的。

    输入格式:

    每个测试输入包含 1 个测试用例。第 1 行给出一个正整数 n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过 100,且不包含空格。

    输出格式:

    每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出 YES,否则输出 NO。

    输入样例:

    8 PAT PAAT AAPATAA AAPAATAAAA xPATx PT Whatever APAAATAA

    输出样例:

    YES YES YES YES NO NO NO NO #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <vector> #include <ctime> #include <cctype> #include <bitset> #include <utility> #include <sstream> #include <complex> #include <iomanip> #include <numeric> #include<unordered_set> #include <climits>//INT_maxnn //#include<bits/stdc++.h> #define PP pair<ll,int> #define inf 0x3f3f3f3f #define INF 0x7fffffff; #define llinf 0x3f3f3f3f3f3f3f3fll #define dinf 1000000000000.0 #define PI 3.1415926 #define LL unsigned int #define wc 1e-8 typedef long long ll; using namespace std; int n; string s; int main(){ cin>>n; while(n--){ cin>>s; int cd=s.size(); int ctl=0,ctr=0,ctm=0,twz=0,pwz=0,cta=0,ctp=0,ctt=0; for(int i=0;i<cd;i++){ if(s[i]=='P'){ pwz=i; ctp++; } else if(s[i]=='A') cta++; else if(s[i]=='T'){ twz=i; ctt++; } } if(ctp!=1||ctt!=1||cta==0||ctp+cta+ctt!=cd||pwz>twz){ cout<<"NO"<<endl; continue; } else{ ctl=pwz; ctm=twz-pwz-1; ctr=cd-twz-1; if(ctr==ctl*ctm) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; }

     

    Processed: 0.019, SQL: 8