50分求改

P1042 [NOIP2003 普及组] 乒乓球

Axolotlwww @ 2024-10-13 00:48:10

源码:

#include<bits/stdc++.h>
using namespace std;

string s;

void f(int rad){
    int a,b,t;
    a=b=t=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='E') break;
        if(s[i]=='W') a++;
        else if(s[i]=='L') b++;
        t++;
        if(t>=rad&&abs(a-b)>=2){
            cout<<a<<":"<<b<<endl;
            a=b=t=0;
        }
    }
    if(a!=0||b!=0) cout<<a<<":"<<b<<endl;

    return;
}

int main(){
    string tmp;
    while(cin>>tmp) s+=tmp;
    if(s[0]=='E') cout<<"0:0\n\n0:0";
    f(11);
    cout<<endl;
    f(21);

    return 0;
}

by Axolotlwww @ 2024-10-13 01:02:24

以一种奇怪的方式解决了(重写

没看明白原理

90分的:

#include<bits/stdc++.h>
using namespace std;

string s;

void f(int rad){
    int a,b;
    a=b=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='E') break;
        if(s[i]=='W') a++;
        else if(s[i]=='L') b++;
        if((a>=rad||b>=rad)&&abs(a-b)>=2){
            cout<<a<<":"<<b<<endl;
            a=b=0;
        }
    }
    if(a!=0||b!=0) cout<<a<<":"<<b<<endl;

    return;
}

int main(){
    string tmp;
    while(cin>>tmp) s+=tmp;
    if(s[0]=='E') cout<<"0:0\n\n0:0";
    f(11);
    cout<<endl;
    f(21);

    return 0;
}

AC(憋抄啊):

#include<bits/stdc++.h>
using namespace std;

char s[25*2500+10];
int cnt=0;

void f(int rad){
    int a,b;
    a=b=0;
    for(int i=0;i<cnt;i++){
        if(s[i]=='W') a++;
        else if(s[i]=='L') b++;
        if((a>=rad||b>=rad)&&abs(a-b)>=2){
            cout<<a<<":"<<b<<endl;
            a=b=0;
        }
    }
    cout<<a<<":"<<b<<endl;

    return;
}

int main(){
    char tmp;
    while(cin>>tmp&&tmp!='E') s[cnt++]=tmp;
    f(11);
    cout<<endl;
    f(21);

    return 0;
}

by XURUIFAN @ 2024-10-13 06:54:35

50那个如果WEWEW这种数据你咋搞,那个t计数容易被卡掉
(熬夜对身体不好)


by codebot @ 2024-10-16 16:42:22

简单明了@Axolotlwww

#include <iostream>
#include <string>
using namespace std;
char s[1000001];
int i, j, length = 0;
int part1 = 0, part2 = 0;
void imm(int n)
{
    for (i = 0 ; i < length ; i++){
        if (s[i] == 'W'){
            part1++;
        }else if (s[i] == 'L'){
            part2++;
        }
        if ((part1 >= n || part2 >= n) && abs(part1 - part2) >= 2){
            cout << part1 << ':' << part2 << endl;
            part1 = 0;
            part2 = 0;
        }
    }
    cout << part1 << ':' << part2 << endl;
}
int main()
{
    char c;
    while (cin >> c && c != 'E'){
        s[length++] = c;
    }
    imm(11);
    part1 = part2 = 0;
    cout << endl;
    imm(21);
}

|