HELP! 10pts

P1042 [NOIP2003 普及组] 乒乓球

STEAMZzR01024602 @ 2024-07-12 10:08:17

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h1=0,h2=0,h3=0,d1=0,d2=0,d3=0,a1=0,a2=0,a3=0,b1=0,b2=0,b3=0;
    char a;
    while(cin>>a)
    {
        if(a=='E') 
        {
            if(h1>0&&d1>=0||h1>=0&&d1>0) cout<<h1<<":"<<d1<<endl;
            if(h1<11&&d1<11) break;
            if(h1==0&&d1==0)
            {
                cout<<0<<":"<<0<<endl;
                break;
            }
            if(h2>0&&d2>=0||h2>=0&&d2>0) cout<<h2<<":"<<d2<<endl;
            if(h2<11&&d2<11) break;
            if(h2==0&&d2==0)
            {
                cout<<0<<":"<<0<<endl;
                break;
            }
            if(h3>0&&d3>=0||h3>=0&&d3>0) cout<<h3<<":"<<d3<<endl;
            if(h3<11&&d3<11) break;
            if(h3==0&&d3==0)
            {
                cout<<0<<":"<<0<<endl;
                break;
            }
            break;
        }
        if(a=='W')
        {
            if(h1<11&&d1<11) h1++;
            else if(h1==11||d1==11)
            {
                if(h2<11&&d2<11) h2++;
                else if(h2==11||d2==11)
                {
                    if(h3<11&&d3<11) h3++;
                }
            }
            if(a1<21&&b1<21) a1++;
            else if(a1==21||b1==21)
            {
                if(a2<21&&b2<21) a2++;
                else if(a2==21||b2==21)
                {
                    if(a3<21&&b3<21) a3++;
                }
            }
        }
        if(a=='L')
        {
            if(h1<11&&d1<11) d1++;
            else if(h1==11||d1==11)
            {
                if(h2<11&&d2<11) d2++;
                else if(h2==11||d2==11)
                {
                    if(h3<11&&d1<11) d3++;
                }
            }
            if(a1<21&&b1<21) b1++;
            else if(a1==21||b1==21)
            {
                if(a2<21&&b2<21) b2++;
                else if(a2==21||b2==21)
                {
                    if(a3<21&&b3<21) b3++;
                }
            }
        }
    }
    cout<<endl;
    if(a1>0&&b1>=0||a1>=0&&b1>0) cout<<a1<<":"<<b1<<endl;
    if(a1<11&&b1<11) return 0;
    if(a1==0&&b1==0)
    {
        cout<<0<<":"<<0<<endl;
        return 0;
    }
    if(a2>0&&b2>=0||a2>=0&&b2>0) cout<<a2<<":"<<b2<<endl;
    if(a2<11&&b2<11) return 0;
    if(a2==0&&b2==0)
    {
        cout<<0<<":"<<0<<endl;
        return 0;
    }
    if(a3>0&&b3>=0||a3>=0&&b3>0) cout<<a3<<":"<<b3<<endl;
    if(a3<11&&b3<11) return 0;
    if(a3==0&&b3==0)
    {
        cout<<0<<":"<<0<<endl;
        return 0;
    }
    return 0;
}

by xie_jing_ao @ 2024-07-12 10:15:34

每次循环后要清零求关


by osu_rice222 @ 2024-07-12 10:28:39


#include <bits/stdc++.h>
using namespace std;
string s,t;
int main(){
    while(cin>>t){
        s+=t;
    }
    int w=0,l=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            w++;
        }
        if(s[i]=='L'){
            l++;
        }
        if((w>=11||l>=11)&&(w-l>=2||l-w>=2)){
            cout<<w<<":"<<l<<'\n';
            w=0,l=0;
        }
        if(s[i]=='E'){
            cout<<w<<":"<<l<<'\n';
            w=0,l=0;
            break;
        }
    }
    cout<<'\n';
    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            w++;
        }
        if(s[i]=='L'){
            l++;
        }
        if((w>=21||l>=21)&&(w-l>=2||l-w>=2)){
            cout<<w<<":"<<l<<endl;
            w=0,l=0;
        }
        if(s[i]=='E'){
            cout<<w<<":"<<l;
            w=0,l=0;
            break;
        }
    }
    return 0;
}
本人蒟蒻,勿喷

by STEAMZzR01024602 @ 2024-07-18 09:27:56

@xie_jing_ao 感谢,已关


by STEAMZzR01024602 @ 2024-07-18 09:30:02

@zsedcftgb @xie_jing_ao 已经AC了,谢谢


by STEAMZzR01024602 @ 2024-07-18 09:33:20

此帖结


|