您的位置:首页 > 编程语言

PAT——乙级真题1003代码

2015-11-09 17:34 309 查看


#include<iostream>
#include<string>
using namespace std;

int getLength(string str0);
int main(){
int n, index=0;
cin>>n;

//define dynamic array
string *str=new string
;

//initialize the array
for(int i=0;i<n;i++){
cin>>str[i];
}

//deal with the data

for(int j=0;j<n;j++){
int posp=-1, post=-1, nump=0, numt=0, ok=0,firstA=0, mediumA=0, lastA=0, other=0;
string pat=str[j];
int len=getLength(pat);

for(int n=0;n<len;n++){
if(pat
=='P'){
posp=n;
nump++;
}else
if(pat
=='T'){
post=n;
numt++;
}else
if(pat
!='A'&&pat
!=' ')
other++;

}

if(other==0&&nump==1&&numt==1&&post>posp){
firstA=posp;
mediumA=post-posp-1;
lastA=len-post-1;

if(firstA==0&&lastA==0&&mediumA>=1)ok=1;
if(firstA>0&&lastA>0&&lastA==firstA*mediumA)ok=1;

if(ok==0)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}else
cout<<"NO"<<endl;

}
return 0;
}
int getLength(string str0){
int i=0;
while (str0[i]!='\0')i++;
return i;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: