1922:【03NOIP普及组】乒乓球

信息学奥赛一本通1922:【03NOIP普及组】乒乓球的详细解法以及思路
问题超时

//1922:乒乓球
#include<bits/stdc++.h>
using namespace std;
long long s=0;
int max=0;
int t=0;
char a[500000005];
long long win=0;
long long lost=0;
int print(long long x,long long y)
{
    printf("%d:%d\n",x,y);
}
int main(){
        int s=0;
        while(a[s] != 'E')
        {
            cin>>a[s];
            s++;
        }
        for(int i=0;i<s;i++)
        {
            if(a[i] == 'W')
            {
                win++;    
            }
            else if(a[i] == 'L')
            {
                lost++;
            }
            if(win == 11)
            {
                print(win,lost);
                win-=11;
            }
            if(a[i] == 'E')
            {
                print(win,lost);
                break;
            }
        }    
        cout<<endl;
        
        win=0;
        lost=0;
        for(int i=0;i<s;i++)
        {
            if(a[i]=='W')
            {
                win++;
            }
            else if(a[i] == 'L')
            {
                lost++;
            }
            if(win == 21)
            {
                print(win,lost);
                win-=21;
            }
            if(a[i] == 'E')
            {
                print(win,lost);
                break;
            }
            
        }
        return 0;
} 


#include<bits/stdc++.h> 
using namespace std;
char ch, a[62505];
int main(){
    int i=0, huahua=0, duishou=0, tmp = 0, flag = 1;
    while(cin >> ch && ch != 'E')
        a[i++] = ch;
    for(int j=0; j<i; j++){
        if(a[j] == 'W')    huahua++;
        else duishou++;
        if((huahua>=11 || duishou>=11) && abs(huahua - duishou) >= 2){//有一方达到11分,且两者分数差2分以上(包括2分)
            cout << huahua << ":" << duishou << endl;
            huahua = duishou = 0;
        }
    }
    cout << huahua << ":" << duishou << endl << endl;
    huahua = duishou = 0;
    for(int j=0; j<i; j++){
        if(a[j] == 'W')    huahua++;
        else duishou++;
        if((huahua>=21 || duishou>=21) && abs(huahua - duishou) >= 2){//有一方达到21分,且两者分数差2分以上(包括2分)
            cout << huahua << ":" << duishou << endl;
            huahua = duishou = 0;
        }
    }
    cout << huahua << ":" << duishou << endl;
    return 0;
}