PAT——乙级真题1003代码

PAT——乙级真题1003代码

#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[n]; //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[n]=='P'){
posp=n;
nump++;
}else
if(pat[n]=='T'){
post=n;
numt++;
}else
if(pat[n]!='A'&&pat[n]!=' ')
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;
}
上一篇:机器学习03:K近邻算法


下一篇:【搬运】Tea算法Java实现工具类