我要通过!(20)
来源:互联网 发布:淘宝安德鲁吉他怎么样 编辑:程序博客网 时间:2024/06/07 07:26
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 <iostream>
#include<string>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void panduan(string s)
{
if(s[0]=='P'&&s[1]=='A'&&s[2]=='T'&&s.length()==3)
{
cout<<"YES";
}
else
{
int i=0;
int n=s.length();
int u=0;
while(u<n)
{
if(s[u]!='P'&&s[u]!='A'&&s[u]!='T'&&s[u]!=' ')
{
cout<<"NO";
return;
}
u++;
}
while(s[i]!='P')
i++;
int a=i;
while(s[i]!='T')
i++;
int b=i;
if(b-a==1)
cout<<"NO";
else if(a<b&&a*(b-a-1)==n-(b+1))
cout<<"YES";
else
cout<<"NO";
}
}
int main(int argc, char** argv)
#include<string>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void panduan(string s)
{
if(s[0]=='P'&&s[1]=='A'&&s[2]=='T'&&s.length()==3)
{
cout<<"YES";
}
else
{
int i=0;
int n=s.length();
int u=0;
while(u<n)
{
if(s[u]!='P'&&s[u]!='A'&&s[u]!='T'&&s[u]!=' ')
{
cout<<"NO";
return;
}
u++;
}
while(s[i]!='P')
i++;
int a=i;
while(s[i]!='T')
i++;
int b=i;
if(b-a==1)
cout<<"NO";
else if(a<b&&a*(b-a-1)==n-(b+1))
cout<<"YES";
else
cout<<"NO";
}
}
int main(int argc, char** argv)
{
int n;
cin>>n;
string s[10];
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<n;i++)
{
panduan(s[i]);
if(i!=n-1)
cout<<endl;
}
return 0;
}
int n;
cin>>n;
string s[10];
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<n;i++)
{
panduan(s[i]);
if(i!=n-1)
cout<<endl;
}
return 0;
}
0 0
- 我要通过!(20)
- PAT1003我要通过(20)
- 1003. 我要通过!(20)
- PAT_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)
- 查看selenium版本的方法
- 边缘检测算法、平滑方法和锐化方法
- lua中最好不要使用继承
- 10002---如何在已经存在python2的linux环境上安装python3
- Javascript中的apply、call、bind
- 我要通过!(20)
- java学习笔记<一> 继承与接口
- phpstorm 免费激活码
- 跟我学python之mysql操作详解 一、查询操作
- Java中的PriorityQueue的使用提示
- 安装redis
- 学习笔记,关于二叉树。
- 南阳理工ACM 题目85 有趣的数
- 一次高并发下生成js随机数的实践