起因是第二个测试点错了(只对了1和10),结果我就打印了结果,一个一个对,不是一样的吗?代码:
#include<iostream>
#include<string>
using namespace std;
string str1, str2;
void Out(int num){
int per1 = 0, per2 = 0;
for (int i = 0; i < str1.size(); i++){
if (str1[i] == 'W') per1++;
else per2++;
if ((per1 >= num || per2 >= num) && abs(per1 - per2) >= 2) {
cout << per1 << ":" << per2 << endl;
per1 = 0, per2 = 0;
}
}
cout << per1 << ":" << per2 << endl;
}
int main(){
while (getline(cin,str2)){
int pos = str2.find('E');
if (pos == -1) str1 += str2;
else {
str1 += string(str2.begin(), str2.begin() + pos);
break;
}
str2.clear();
}
Out(11);
cout << endl;
Out(21);
return 0;
}