PAT 1003. 我要通过!(20)
来源:互联网 发布:网络棋牌赌博举报没用 编辑:程序博客网 时间:2024/06/06 07:47
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。
得到“答案正确”的条件是:
1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;
2. 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串;
3. 如果 aPbTc 是正确的,那么 aPbATca 也是正确的,其中 a, b, c 均或者是空字符串,或者是仅由字母 A 组成的字符串。
输入格式: 每个测试输入包含1个测试用例。第1行给出一个自然数n (<10),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过100,且不包含空格。
输出格式:每个字符串的检测结果占一行,如果该字符串可以获得“答案正确”,则输出YES,否则输出NO。
输入样例:8PATPAATAAPATAAAAPAATAAAAxPATxPTWhateverAPAAATAA输出样例:
YESYESYESYESNONONONO
#include <iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ string s; cin>>s; int len=s.length(); int num_p=0,num_t=0,other=0; int loc_p=-1,loc_t=-1; for(int i=0;i<len;i++){ if(s[i]=='P'){ num_p++; loc_p=i; }else if(s[i]=='T'){ num_t++; loc_t=i; }else if(s[i]!='A'){ other++; } } if((num_p!=1)||(num_t!=1)||(other!=0)||(loc_t-loc_p<=1)){ cout<<"NO"<<endl; continue; } int x=loc_p,y=loc_t-loc_p-1,z=len-loc_t-1; if(z-x*(y-1)==x) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
阅读全文
0 0
- PAT 1003. 我要通过!(20)
- PAT 1003. 我要通过!(20)
- PAT - 1003. 我要通过!(20)
- [PAT]1003. 我要通过!(20)
- PAT basic 1003. 我要通过!(20)
- [PAT]1003. 我要通过!(20)
- PAT 1003. 我要通过!(20)
- PAT 1003. 我要通过!(20)
- [PAT]1003. 我要通过!(20)
- PAT 1003. 我要通过!(20)
- Java - PAT - 1003. 我要通过!(20)
- PAT-乙级-1003. 我要通过!(20)
- 1003. 我要通过!(20) PAT乙级
- PAT-B 1003. 我要通过!(20)
- PAT-B 1003. 我要通过!(20)
- 1003. 我要通过!(20)-PAT乙级
- 1003. 我要通过!(20) PAT
- PAT乙级 1003. 我要通过!(20)
- GitHub控件之BadgeView(数字提醒)
- 微信开发:js sdk 分享(java)
- md5加密,第二次加密,解密
- 一分钟教会你如何做自媒体淘客
- Swift之类与结构体
- PAT 1003. 我要通过!(20)
- 0912 Oracle函数
- 【cuda】This graphics driver could not find compatible graphics hardware..
- 关于ppp、PPPoE、PPTP、L2TP、IPSec协议的简单认识
- 2017.9.13 找硬币 失败总结
- echart柱形图上面显示内容
- CodeForces 493 E.Vasya and Polynomial(数学)
- Spark连接MongDB
- The Little Schemer读书笔记1