通过了,有没有大佬给更优解
查看原帖
通过了,有没有大佬给更优解
1053240
Liu_Zi_Xiao楼主2024/3/31 11:12

求大佬给更优解

#include<bits/stdc++.h>
using namespace std;
char c[62530];
int n,m;
int main(){
	for(int i=0;c[i-1]!='E';++i) scanf("%c",&c[i]);
	for(int i=0;c[i]!='E';++i){
		if(c[i]=='W') ++n;
		else if(c[i]=='L') ++m;
		if( (n>=11 && n-m>=2) || (m>=11 && m-n>=2) ){
			cout<<n<<':'<<m<<endl;
			n=0;
			m=0;
		}
	}
	cout<<n<<':'<<m;
	cout<<endl<<endl;
	n=0;
	m=0;
	for(int i=0;c[i]!='E';++i){
		if(c[i]=='W') ++n;
		else if(c[i]=='L') ++m;
		if( (n>=21 && n-m>=2) || (m>=21 && m-n>=2) ){
			cout<<n<<':'<<m<<endl;
			n=0;
			m=0;
		}
	}
	cout<<n<<':'<<m;
	return 0;
}

2024/3/31 11:12
加载中...