PATB1003.我要通过(20)
2018-02-25 17:10
120 查看
题目链接:点击打开链接
知识点笔记:
AC代码:
#include <iostream> #include <cstring> using namespace std; int main() { int n; char str[100]; scanf("%d",&n); while(n--){ scanf("%s",str); int len = strlen(str); int others=0; int P=0,T=0; int posP,posT; for(int i=0;i<len;i++){ if(str[i]=='P'){ P++; posP=i; }else if(str[i]=='T'){ T++; posT=i; }else if(str[i]!='A'){ others++; } } //如果有其他字符,或者PT的数量不是1 ,或者PT之间没有A(这种容易忽略) if(others>0||P!=1||T!=1||posT-posP<=1) printf("NO\n"); else{ int x=posP; //P之前A的个数 int y=posT-posP-1; //PT之间A的个数 int z=len-posT-1; //T之后A的个数 if(x*y==z) printf("YES\n"); else printf("NO\n"); } } return 0; }
相关文章推荐
- PAT 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- PAT 1003. 我要通过!(20)
- 【PAT】(乙级)1003. 我要通过!(20)
- PAT乙级 1003. 我要通过!(20)
- PAT(乙)-1003.我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- 1003 我要通过!(20)
- 1003. 我要通过!(20)
- 1003. 我要通过!(20)
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20)
- 1003. 我要通过!(20) JAVA pattern