虽然AC了,但为啥for循环里后两个if语句一模一样
查看原帖
虽然AC了,但为啥for循环里后两个if语句一模一样
331785
20230131汤阅宸楼主2021/9/14 16:08
#include<bits/stdc++.h>
using namespace std;
char ch[62515];
int win,lose,n;//win代表胜利场数,lose代表失败场数,n储存ch数组的长度
int main(){
	while(cin>>ch[n]){//输入
		if(ch[n]=='E')break;//输入到E的时候停止,因为E之后的符号会影响代码的正常运行
		n++;//边输入边计数,循环结束后的n就代表了ch数组的长度
	}
	for(int i=0;i<n;i++){
		if(ch[i]=='W')//赢了的话win++
			win++;
		if(ch[i]=='L')//输了的话lose++
			lose++;
		if(abs(win-lose)>=2 && (win==11 || lose==11)){
			cout<<win<<":"<<lose<<endl;
			win=0;//清零,重新计数,代表一次比赛结束
			lose=0;//同上
		}
		if(abs(win-lose)>=2 && (win>=11 || lose>=11)){
			cout<<win<<":"<<lose<<endl;
			win=0;
			lose=0;
		}
	}
	cout<<win<<":"<<lose<<endl;
	win=0;
	lose=0;
	cout<<endl;
//------------------------以上为11分制
//------------------------以下为21分制
	for(int i=0;i<n;i++){
		if(ch[i]=='W')
			win++;
		if(ch[i]=='L')
			lose++;
		if(abs(win-lose)>=2 && (win==21 || lose==21)){
			cout<<win<<":"<<lose<<endl;
			win=0;
			lose=0;
  		}
		if(abs(win-lose)>=2 && (win>=21 || lose>=21)){
			cout<<win<<":"<<lose<<endl;
			win=0;
			lose=0;
		}
	}
	cout<<win<<":"<<lose;
	return 0;
}
2021/9/14 16:08
加载中...