80pts求调

P1042 [NOIP2003 普及组] 乒乓球

JustinXie @ 2024-06-30 23:41:44

剩两个点求dalao帮忙看下,死活过不去

#include<bits/stdc++.h>
using namespace std;
string s;
char c;
int h11,d11,h21,d21;
int main()
{
    while(cin>>c)
    {
        if(c=='E')
        {
            break;
        }
        s+=c;
    }
    int i=0;
    //11分制
    while(i<s.size())
    {
        if(s[i]=='W')
        {
            h11++;
        }
        else if(s[i]=='L')
        {
            d11++;
        }
        if((h11>=11 || d11>=11) && (h11-d11>=2 || d11-h11>=2) || i==s.size()-1)
        {
            printf("%d:%d\n",h11,d11);
            h11=0;
            d11=0;
        }
        i++;
    }
    i=0;
    cout<<endl;
    //21分制
    while(i<s.size())
    {
        if(s[i]=='W')
        {
            h21++;
        }
        else if(s[i]=='L')
        {
            d21++;
        }
        if((h21>=21 || d21>=21) && (h21-d21>=2 || d21-h21>=2) || i==s.size()-1)
        {
            printf("%d:%d\n",h21,d21);
            h21=0;
            d21=0;
        }
        i++;
    }
    return 0;
}

by huangshuchang @ 2024-07-01 08:16:16

@JustinXie 求关注

#include<bits/stdc++.h>
using namespace std;
char s[100010];
int cnt=0;
void tf(int x){
    int n=0,m=0;
    for(int i=0;i<cnt;i++){
        if(s[i]=='W') n++;
        if(s[i]=='L') m++;
        if((n>=x||m>=x)&&abs(n-m)>=2){
            cout<<n<<":"<<m<<endl;
            n=0;
            m=0;
        }
    }
    cout<<n<<":"<<m<<endl;
}

int main(){
    char ch;
    while(1){
        cin>>ch;
        if(ch=='W'||ch=='L'){
          s[cnt++]=ch;
        }
        if(ch=='E'){
            break;
        }
    }
    tf(11);cout<<endl;tf(21);

}

by JustinXie @ 2024-07-01 11:30:38

感谢!


|