满江红求调

P1042 [NOIP2003 普及组] 乒乓球

xiesichen666 @ 2024-10-14 21:49:05

#include<bits/stdc++.h>
//#include<windows.h>
using namespace std;
int main(){
    char a[1001];
    int i=-1;
    do{
        i++;
        cin>>a[i];
    }while(a[i]!='E');
    int hua=0,dui=0;
    //11:
    for(int j=0;j<=i;j++){
        if(a[j]=='W')hua++;
        if(a[j]=='L')dui++;

        if(hua+dui==11){
            cout<<hua<<':'<<dui<<'\n';
            hua=0,dui=0;
        }
        if(a[j-1]=='E'){
            printf("%d:%d",hua,dui);
            break;
        }
    }
    cout<<'\n';
    //21:
    hua=0;dui=0;
    for(int j=0;j<=i;j++){
        if(a[j]=='W')hua++;
        if(a[j]=='L')dui++;

        if(hua+dui==21){
            cout<<hua<<':'<<dui<<'\n';
            hua=0,dui=0;
        }
        if(a[j-1]=='E'){
            printf("%d:%d",hua,dui);
            break;
        }
    }
    return 0;
}

满江红!!!

求调please


by xiesichen666 @ 2024-10-14 21:50:39

@chen_rcc I don't know


by chen_rcc @ 2024-10-14 21:51:17

自己去揣摩吧

#include <iostream>
#include<string>
using namespace std;
string x;
string h;
int n,w,l;
int main()
{
    while( cin >> x)
    {
        h=h+x;
    }
    for(int i = 0;i < h.size();i ++)
    {
        if(h [i] == 'W')
        {
            w ++;
        }
        else if (h[i] == 'L')l ++;
        else break;
        if(w >= 11 && w - l >= 2 || l >= 11 && l - w >= 2)
        {
            cout << w << ':' << l << endl;
            w = 0;
            l = 0;
        }
    }
    cout << w << ':' << l << endl << endl;
    w = 0;
    l = 0;
    for(int i = 0;i < h.size();i ++)
    {
        if(h [i] == 'W')
        {
            w ++;
        }
        else if(h[i] == 'L')l ++;
        else break;
        if(w >= 21 && w - l >= 2 || l >= 21 && l - w >= 2)
        {
            cout << w << ':' << l << endl;
            w = 0;
            l = 0;
        }
    }
    cout << w << ':' << l << endl;
    return 0;
}

by ikun_555 @ 2024-10-14 21:51:28

@xiesichen666

#include <bits/stdc++.h>
using namespace std;
void fs(string x, int fen) {
    int a = 0, b = 0;
    for (int i = 0; i < x.size()&& x[i] != 'E'; i ++ ) {
    if (x[i] == 'W') a ++ ;
    else b ++ ;
    if (max(a,b) >= fen && abs(a - b) >= 2) {
        cout<<a<<":"<<b<<endl;
        a = b = 0;
    }
    }
    cout<<a<<":"<<b<<endl;
}
int main() {
    string x, s;
    while(cin>>s){
        x+=s;
    }
    fs(x, 11);
    cout<<endl;
    fs(x, 21);
    return 0;
}

我是这么做的


by cpp_xhq @ 2024-10-16 22:10:24

不是hua+dui==11和hua+dui==21

hua>=11||dui>=11hua>=21||dui>=21

还要注意是:直到分差大于或者等于2,才一局结束。


by guoyanwei120223 @ 2024-10-19 16:12:20

@xiesichen666 ```cpp

include<bits/stdc++.h>

using namespace std; char wl[25*2501]; int main() { char a; int w=0,l=0; for(int i=0;a!='E';i++) { cin>>a; wl[i]=a; } for(int i=0;;i++) { if(wl[i]=='W') w++; if(wl[i]=='L') l++; if(max(w,l)>=11&&abs(w-l)>=2) { cout<<w<<":"<<l<<endl; w=0; l=0; } if(wl[i]=='E') { cout<<w<<":"<<l<<endl; cout<<endl; break; } } w=0,l=0; for(int i=0;;i++) { if(wl[i]=='W') w++; if(wl[i]=='L') l++; if(max(w,l)>=21&&abs(w-l)>=2) { cout<<w<<":"<<l<<endl; w=0; l=0; } if(wl[i]=='E') { cout<<w<<":"<<l<<endl; break; } }

}


|