判断太冗杂,输出不了结果,C++

P1042 [NOIP2003 普及组] 乒乓球

@[CPPgtt01](/user/1259807) ```cpp #include<bits/stdc++.h> using namespace std; const int N=10005; int a[N],a1[N],b[N],b1[N]; char ch; int main(){ int x=1,y=1; while(1){ ch=getchar(); if(ch=='E')break; if(ch=='W'){ a[x]++;b[y]++; if(a[x]>=11&&a[x]-a1[x]>=2)x++; if(b[y]>=21&&b[y]-b1[y]>=2)y++; }else if(ch=='L'){ a1[x]++; b1[y]++; if(a1[x]>=11&&a1[x]-a[x]>=2)x++; if(b1[y]>=21&&b1[y]-b[y]>=2)y++; } } for(int i=1;i<=x;i++){ printf("%d:%d\n",a[i],a1[i]); } puts(""); for(int i=1;i<=y;i++){ printf("%d:%d\n",b[i],b1[i]); } return 0; } ``` 判断(仅供参考)
by ZBXALQX @ 2024-02-05 09:05:00


@[CPPgtt01](https://www.luogu.com.cn/user/1259807)你理解错了,搜一下乒乓球11分制规则
by _jiuye_ @ 2024-02-05 09:25:55


参考代码 ```cpp #include<iostream> #include<string> #include<cmath> using namespace std; char t; int l1,w1,l2,w2,a[10000],b[10000]; int main() { int num=0; do{ cin>>t; if(t=='W'){ w1++; w2++; } else if(t=='L'){ l1++; l2++; } if((w1>=11||l1>=11)&&abs(w1-l1)>=2){ cout<<w1<<":"<<l1<<endl; w1=0; l1=0; } if((w2>=21||l2>=21)&&abs(w2-l2)>=2){ a[++num]=w2; b[num]=l2; w2=0; l2=0; } }while(t!='E'); cout<<w1<<":"<<l1<<endl<<endl; for(int i=1;i<=num;i++){ cout<<a[i]<<":"<<b[i]<<endl; } cout<<w2<<":"<<l2; return 0; } ```
by _jiuye_ @ 2024-02-05 09:28:12


|