50pts,求调!

P1042 [NOIP2003 普及组] 乒乓球

Sun_ZZZ @ 2024-07-10 09:33:19

2、3、4、5、7测点没过

代码:

#include<iostream>
#include<cstdio> 
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int n,a[25*2502],w,l,f[2]={11,21};
int main(){
    char temp;
    while(1){
        cin>>temp; 
        if(temp=='E'){
            break;
        }
        else if(temp=='W'){
            a[n++]=1;
        }
        else if(temp=='L'){
            a[n++]=0;
        }
    }
    for(int k=0;k<2;k++){
        w=0;l=0;
        for(int i=0;i<n;i++){
            w+=a[i];l+=(a[i]==0);
            if(w>=f[k]&&abs(w-l)>=2){
                cout<<w<<":"<<l<<endl;
                w=0;
                l=0;
            }
        }
        cout<<w<<":"<<l<<endl;
        cout<<endl;
    }

    return 0;
}

by PrOI_Luo_Yi_cheng @ 2024-07-10 09:35:44

#include <iostream>
#include <vector>
#include <cctype>
#include <cmath>
#define AUTHOR "HEX9CF"
using namespace std;

char ch;
vector<char> str;

void print(int x)
{
    int f = 1;
    int w = 0;
    int l = 0; 
    for(int i = 0; str[i] != 'E'; i++)
    {
        ch = str[i];
        // cout << ch;
        if ('W' == ch)
        {
            w++;
        }
        else if ('L' == ch)
        {
            l++;
        }
        if ((w >= x || l >= x) && 2 <= abs(w - l))
        {
            cout << w << ':' << l << endl;
            w = 0;
            l = 0;
            f = 0;
        }
    }
    cout << w << ':' << l << endl;
    putchar('\n');
}

int main()
{
    while((ch = getchar()) != 'E'){
        if(isalpha(ch)){
            str.push_back(ch);
        }
    }
    str.push_back('E');
    print(11);
    print(21);
    return 0;
}

by PrOI_Luo_Yi_cheng @ 2024-07-10 09:36:21

点个关注啊!


by Sun_ZZZ @ 2024-07-11 12:31:12

点了,谢谢


|