1003. 我要通过!(20)
来源:互联网 发布:合肥八度网络怎么样 编辑:程序博客网 时间:2024/06/08 18:29
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于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 <string>using namespace std;int main(){ int n; cin >> n; string str; while(n--) { cin >> str; int a = 0, b = 0, c = 0, jud = 0; for(int i = 0; str[i]; i++) { if(str[i] != 'P' && str[i] != 'A' && str[i] != 'T') { cout << "NO"<<endl; jud = 1; break; } } if(jud) continue; int j = 0; while(str[j++] != 'P') a++; while(str[j++] != 'T') b++; while(str[j++]) c++; if(a * b == c && b) cout << "YES"<<endl; else cout << "NO"<<endl; } return 0;}
阅读全文
0 0
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- [MAC]OpenGL中SOIL库与stbi_load库加载图片,透明黑色问题,遇到的坑及解决办法
- MBProgressHUD中0.7版本在ios11上面的小坑
- 共享打印机复印机方案开发
- Adb interface驱动无法安装解决方法!
- cuda 9.0 + vs2015 环境搭建
- 1003. 我要通过!(20)
- linux scp用法
- isset 判断变量是否存在的时候对于0是生效的
- linux cd与ls命令用法
- (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: mak e_sock: could not bind to address [::]:443
- 用IDEA生成webService客户端时抛出Exception in thread "main" java.lang.AssertionError: org.xml.sax.SAXParseExce
- 设计模式--适配器模式
- 通过斐波那契数列查看Python和R的计算速度
- Github使用教程(二)------ Github客户端使用方法