为什么过不了,测试点2的数据和答案是一样的
查看原帖
为什么过不了,测试点2的数据和答案是一样的
1080836
Liuzq12333楼主2023/9/25 13:20
#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<sstream>
using namespace std;

int main() {
	string str;
	string longstr;
	while (getline(cin, str)) {
		
		int loc = str.find('E');
		if (loc != -1) {
			str = str.substr(0,loc);
			longstr += str;
			break;
		}
		longstr += str;
	}
	int size = longstr.size();
	int Win = 0;
	int Lose = 0;
	for (int i = 0; i < size; i++) {
		if ((Win >= 11 || Lose >= 11) && abs(Win - Lose) >= 2) {
			cout << Win << ":" << Lose << endl;
			Win = 0;
			Lose = 0;
			//重置计数器
		}
		if (longstr[i] == 'W') {
			Win++;
		}
		else {
			Lose++;
		}
		
	}
	cout << Win << ':' << Lose << endl;
	cout << endl;

	Win = 0;
	Lose = 0;
	for (int i = 0; i < size; i++) {
		if ((Win >= 21 || Lose >= 21) && abs(Win - Lose) >= 2) {
			cout << Win << ":" << Lose << endl;
			Win = 0;
			Lose = 0;
			//重置计数器
		}
		if (longstr[i] == 'W') {
			Win++;
		}
		else {
			Lose++;
		}

	}
	cout << Win << ':' << Lose << endl;
}

2023/9/25 13:20
加载中...