#include <bits/stdc++.h>
using namespace std;
int eleven[6250][2];
int twelve[6250][2];
int main(){
char now [30];
bool is_end = false;
int a = 11;
int b = 21;
int huahua = 0;
int duishou = 0;
int twe_huahua = 0;
int twe_duishou = 0;
int ele_cnt = 0;
int twe_cnt = 0;
while(true){
if(is_end)break;
cin.getline(now, 30);
int idx = 0;
while(now[idx]!='\0'){
if(now[idx]=='E'){
is_end = true;
eleven[ele_cnt][0] = huahua;
eleven[ele_cnt][1] = duishou;
ele_cnt++;
twelve[twe_cnt][0] = twe_huahua;
twelve[twe_cnt][1] = twe_duishou;
twe_cnt++;
break;
}
if(now[idx]=='W'){
huahua++;
twe_huahua++;
}
else {
duishou++;
twe_duishou++;
}
if((huahua>=11||duishou>=11)&&abs(huahua-duishou)>=2){
eleven[ele_cnt][0] = huahua;
eleven[ele_cnt][1] = duishou;
ele_cnt++;
huahua = 0;
duishou = 0;
}
if((twe_huahua>=21||twe_duishou>=21)&&abs(twe_huahua-twe_duishou)>=2){
twelve[twe_cnt][0] = twe_huahua;
twelve[twe_cnt][1] = twe_duishou;
twe_cnt++;
twe_huahua = 0;
twe_duishou = 0;
}
idx++;
}
}
for(int i=0;i<ele_cnt;i++){
cout<<eleven[i][0]<<":"<<eleven[i][1]<<endl;
}
cout<<endl;
for(int i=0;i<twe_cnt;i++){
cout<<twelve[i][0]<<":"<<twelve[i][1]<<endl;
}
return 0;
}
以上是只跑了20分的,用的cin.getline()
#include <bits/stdc++.h>
using namespace std;
int eleven[6250][2];
int twelve[6250][2];
int main(){
char now [30];
bool is_end = false;
int a = 11;
int b = 21;
int huahua = 0;
int duishou = 0;
int twe_huahua = 0;
int twe_duishou = 0;
int ele_cnt = 0;
int twe_cnt = 0;
while(true){
if(is_end)break;
cin>>now;
int idx = 0;
while(now[idx]!='\0'){
if(now[idx]=='E'){
is_end = true;
eleven[ele_cnt][0] = huahua;
eleven[ele_cnt][1] = duishou;
ele_cnt++;
twelve[twe_cnt][0] = twe_huahua;
twelve[twe_cnt][1] = twe_duishou;
twe_cnt++;
break;
}
if(now[idx]=='W'){
huahua++;
twe_huahua++;
}
else {
duishou++;
twe_duishou++;
}
if((huahua>=11||duishou>=11)&&abs(huahua-duishou)>=2){
eleven[ele_cnt][0] = huahua;
eleven[ele_cnt][1] = duishou;
ele_cnt++;
huahua = 0;
duishou = 0;
}
if((twe_huahua>=21||twe_duishou>=21)&&abs(twe_huahua-twe_duishou)>=2){
twelve[twe_cnt][0] = twe_huahua;
twelve[twe_cnt][1] = twe_duishou;
twe_cnt++;
twe_huahua = 0;
twe_duishou = 0;
}
idx++;
}
}
for(int i=0;i<ele_cnt;i++){
cout<<eleven[i][0]<<":"<<eleven[i][1]<<endl;
}
cout<<endl;
for(int i=0;i<twe_cnt;i++){
cout<<twelve[i][0]<<":"<<twelve[i][1]<<endl;
}
return 0;
}
以上是跑过了的,跟第一个,区别只在于这个用的是cin,而不是cin.getline()
然后我还下载了第二个数据点,两者都能成功打印出答案来,一模一样,但是第一个就是算跑不过,为啥捏......输入数据又没有空格,按理说不会影响的才对。。