只有十分!!大佬捞捞

P1042 [NOIP2003 普及组] 乒乓球

Bettieee @ 2024-12-01 19:42:26

只有十分我已经把读入只限定在L和W里面了,这道题还有其他一易错点吗??呜呜呜救救孩子,大佬捞捞
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 80000
int w=0,l=0;

int min(int a,int b){
    return a<b?a:b;
}
char str[N];
char p[2502][26];
int len;
void ele(int n);
void twn(int n);
int main(void){
int i,j;
len=0;
    for(i=0;i<N;i++){
        char k;
        scanf("%c",&k);
        if(k=='\n')continue;
        else if(k=='E')break;
        else if(k=='L')str[len++]=k;
        else if(k=='W')str[len++]=k;
        else continue;
    }
    len=strlen(str);
    ele(0);
    putchar('\n');
    twn(0);//从零开始的查找数组
    return 0;
}
void ele(int n){
  do{
      if(str[n]=='L')l++;
      else if(str[n]=='W')w++;
      n++;
      if(l+w>=11&&abs(l-w)>=2){printf("%da:%d\n",w,l);l=0;w=0;}
      else if(n==len){printf("%d:%d\n",w,l);l=0;w=0;}

  }while(n<len);
  //return 0;
}

void twn(int n){
  do{
      if(str[n]=='L')l++;
      else if(str[n]=='W')w++;
      n++;
      if(l+w>=21&&abs(l-w)>=2){printf("%d:%d\n",w,l);l=0;w=0;}
      else if(n==len){printf("%d:%d\n",w,l);l=0;w=0;}

  }while(n<len);

}

by ycyjx @ 2024-12-07 16:20:37

#include<bits/stdc++.h>
using namespace std;
char s;
int a[1000001]={};
int main(){
    int n=1,w=0,l=0;
    while (cin>>s&&s!='E'){
        if (s=='W')a[n]=1;
        else if (s=='L')a[n]=2;
        n++;
    }
    for (int i=1;i<=n;i++){
        if (a[i]==1)w++;
        if (a[i]==2)l++;
        if (a[i]==0){
            cout<<w<<":"<<l<<endl<<endl;
            break;
        }
        if (abs(w-l)>=2){
            if (w>=11||l>=11){
                cout<<w<<":"<<l<<endl;
                w=0;
                l=0;
            }
        }
    }
    w=0;
    l=0;
    for (int i=1;i<=n;i++){
        if (a[i]==1)w++;
        if (a[i]==2)l++;
        if (a[i]==0){
            cout<<w<<":"<<l<<endl<<endl;
            break;
        }
        if (abs(w-l)>=2){
            if (w>=21||l>=21){
                cout<<w<<":"<<l<<endl;
                w=0;
                l=0;
            }
        }
    }
    return 0;
}

by ycyjx @ 2024-12-07 16:22:46

直接遍历,不用那么麻烦!!!


|