P1042 乒乓球

#include<bits/stdc++.h> 
using namespace std;
int main()
{
	freopen("in.txt","r",stdin);
	string s;int flag=0;
	while(1){
		string temp;
		//getline(cin,temp);//这里不能用getline,或者我的getline用错了
		cin>>temp;
		for(int i=0;i<temp.length();i++){
			if(temp[i]!='E'){
				s+=temp[i];
			}else{
				flag=1;break;
			} 
		}
		if(flag==1) break;
	} 
	int score1=0,score2=0;
	for(int i=0;i<s.length();i++){
		
		if(s[i]=='W'){
			score1++;
		}else{
			score2++;
		}
		if(abs(score1-score2)>=2&&(score1>=11||score2>=11)){
			cout<<score1<<":"<<score2<<endl;
			score1=0;score2=0;
		}
	}
	cout<<score1<<":"<<score2<<endl;
	cout<<endl;
	int score11=0,score22=0;
	for(int i=0;i<s.length();i++){
		
		if(s[i]=='W'){
			score11++;
		}else{
			score22++;
		}
		if(abs(score11-score22)>=2&&(score11>=21||score22>=21)){
			cout<<score11<<":"<<score22<<endl;
			score11=0;score22=0;
		}
	}
	cout<<score11<<":"<<score22<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/csg3140100993/article/details/82686118