PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
来源:互联网 发布:wifi没网络但是能连上 编辑:程序博客网 时间:2024/05/16 11:22
1003. 我要通过!(20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于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<stdio.h>#include<stdlib.h>#include<string.h>int main(){int n,len,p,a,t,p_pos,t_pos;char str[100];scanf("%d\n",&n);while(n--){gets(str);p = a = t = p_pos = t_pos = 0;len = strlen(str);for(int i = 0;i < len;i++){if(str[i] == 'P'){p++;p_pos = i;}if(str[i] == 'A'){a++;}if(str[i] == 'T'){t++;t_pos = i;}}if(p+a+t != len || p > 1 || t > 1 || p_pos >= t_pos - 1 || p_pos * (t_pos - p_pos - 1) != len - t_pos - 1)printf("NO\n");else printf("YES\n");}return 0;}
0 0
- PAT (Basic Level) Practise (中文) 1003.我要通过
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20) C语言
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文) 1003.我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)—— 1003. 我要通过!
- PAT (Basic Level) Practise 1003. 我要通过!
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- JavaSE基础--(三)面向对象 部分
- C#垃圾回收机制详解
- win7下直接安装win10
- Cocos2d-js打造游戏新手引导(一)
- Java并发编程:volatile关键字解析
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- pkg-config的用法
- Android 开发环境配置图文教程(jdk+eclipse+android sdk)
- Oracle学习笔记20150815多表查询
- 11个让你吃惊的linux命令
- 图片下载器类
- spring 事物管理
- Cocos2d-js制作游戏新手引导(二)
- Git 远程协作