洛谷p1042 运行结果错误 想知道怎么改

https://www.luogu.com.cn/problem/P1042


#include<iostream>
#include<cmath>
using namespace std;
int main(){
 int a[2][9999],b[2][9999];
 int a1=0,a2=0,b1=0,b2=0;
 int count1=0,count2=0;
 char str;
 for(int i=0;cin>>str&&str!='E';i++){
  if(str=='W'){
   a1++;//11分制 
   b1++;//21分制 
  }
  else{
   a2++;
   b2++;
  }
    if(abs(a1-a2)>=2||(a1>=11||a2>=11)){
     a[0][count1]=a1;
     a[1][count1]=a2;
     a1=a2=0;
     count1++;
 }
 if(abs(b1-b2)>=2||(b1>=21||b2>=21)){
  b[0][count2]=b1;
  b[1][count2]=b2;
  b1=b2=0;
  count2++;
 }
}
bool flag1=0,flag2=0;
for(int i=0;i<count1;i++){
 cout<<a[0][i]<<":"<<a[1][i]<<endl;
}
 if(a1!=0||a2!=0){
  cout<<a1<<":"<<a2<<endl;
  flag1=1;
 }
 if(flag1==0){
  cout<<0<<":"<<0<<endl;
 }
cout<<endl;
for(int i=0;i<count2;i++){
 cout<<b[0][i]<<":"<<b[1][i]<<endl;
}
 if(b1!=0||b2!=0){
  cout<<b1<<":"<<b2<<endl;
  flag2=1;
 }
 if(flag2==0){
  cout<<0<<":"<<0<<endl;
 }

 return 0;
}

谢谢大家!

img