首页 > 其他 > 详细

PAT——乙级真题1003代码

时间:2015-11-09 18:44:43      阅读:327      评论:0      收藏:0      [点我收藏+]

技术分享

#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;
}

 

PAT——乙级真题1003代码

原文:http://www.cnblogs.com/no-tears-girl/p/4950582.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!