PAT 1003 我要通过
2016-08-21 09:29
190 查看
这个题看似有很多条件需要考虑,第一次看到这个题的时候有点不知所措。
其实总结起来,只有两种情况能满足题目的条件,打印YES,其他的都是
打印NO。一是只有PAT,当然是可以通过的,还有一种情况就是P前面的A
乘P和T之间的A等于T后面的A。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
char ch[200];
int idxP,idxT,len;
scanf("%s",ch);
string s = string(ch);
idxP=s.find('P',0);
idxT=s.find('T',0);
len=s.length();
if (idxP==string::npos||idxT==string::npos||idxP>=idxT-1)
{
printf("NO\n");
}
else
{
string a(s,0,idxP);
string b(s,idxP+1,idxT-idxP-1);
string c(s,idxT+1,len-idxT-1);
string ans=a+b+c;
if (ans.find_first_not_of('A')!=string::npos)
{
printf("NO\n");
}
else
{
if (idxP==0||len+-idxT-1==0)
{
printf("YES\n");
}
else if (idxP*(idxT-idxP-1)==len-idxT-1)
{
printf("YES\n");
}
else printf("NO\n");
}
}
}
return 0;
}
其实总结起来,只有两种情况能满足题目的条件,打印YES,其他的都是
打印NO。一是只有PAT,当然是可以通过的,还有一种情况就是P前面的A
乘P和T之间的A等于T后面的A。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
char ch[200];
int idxP,idxT,len;
scanf("%s",ch);
string s = string(ch);
idxP=s.find('P',0);
idxT=s.find('T',0);
len=s.length();
if (idxP==string::npos||idxT==string::npos||idxP>=idxT-1)
{
printf("NO\n");
}
else
{
string a(s,0,idxP);
string b(s,idxP+1,idxT-idxP-1);
string c(s,idxT+1,len-idxT-1);
string ans=a+b+c;
if (ans.find_first_not_of('A')!=string::npos)
{
printf("NO\n");
}
else
{
if (idxP==0||len+-idxT-1==0)
{
printf("YES\n");
}
else if (idxP*(idxT-idxP-1)==len-idxT-1)
{
printf("YES\n");
}
else printf("NO\n");
}
}
}
return 0;
}
相关文章推荐
- PAT(Basic Level)_1003_我要通过!
- PAT 1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- PAT Basic Level 1003. 我要通过!(20)
- PAT BASIC LEVEL 1003. 我要通过!(20)
- PAT(BL)1003_我要通过
- PAT 1003. 我要通过!(20) —— java
- PAT 1003. 我要通过!(20)
- PAT1003. 我要通过!(C语言实现,多种解法)
- PAT1003 我要通过
- PAT1003 我要通过!
- PAT basic 1003. 我要通过!(20)
- PAT-B 1003. 我要通过!(20)
- PAT乙级1003我要通过!(20)
- PAT_乙级1003. 我要通过!(20)
- PAT 乙级 1003. 我要通过!
- PAT 1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- 1003. 我要通过!(20) PAT乙级
- PAT乙级1003. 我要通过!(20)