KARA_214 @ 2024-08-08 15:54:32
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
char c;
int n(0),a[70000],f,cnt1(0),cnt2(0),tmp(0);
int main(){
while(1){
cin>>c;
if(c=='E'){break;tmp++;}
else if(c=='W'){
a[f++]+=1;
tmp++;
}else if(c=='L'){
a[f++]+=0;
tmp++;
}
}
for(int i=1;i<=tmp;i++){
if(a[i]==1){
cnt1++;
cnt2+=1-a[i];
if(abs(cnt1-cnt2)>=2&&max(cnt1,cnt2)>=11){
cout<<cnt1<<":"<<cnt2<<endl;
cnt1=cnt2=0;
}
if(i==tmp){
cout<<cnt1<<":"<<cnt2<<endl;
break;
}
}
}
cout<<endl;
for(int i=1;i<=tmp;i++){
if(a[i]==1){
cnt1++;
cnt2+=1-a[i];
if(abs(cnt1-cnt2)>=2&&max(cnt1,cnt2)>=21){
cout<<cnt1<<":"<<cnt2<<endl;
cnt1=cnt2=0;
}
if(i==tmp){
cout<<cnt1<<":"<<cnt2<<endl;
break;
}
}
}
return 0;
}
这是它的输出:
11:0
11:0
21:0 同学们求助
by xujiacheng0312 @ 2024-08-08 16:23:35
AC
#include <bits/stdc++.h>//乒乓球
using namespace std;
const int N=5e3+10;
int a[N],b[N],d[N],c[N],l1,l2;
int main()
{
char s;
cin>>s;
while(s!='E')
{
if(s=='W') a[l1]++,c[l2]++;
if(s=='L') b[l1]++,d[l2]++;
if((a[l1]>=11&&a[l1]-b[l1]>=2)||(b[l1]>=11&&b[l1]-a[l1]>=2)) l1++;
if((c[l2]>=21&&c[l2]-d[l2]>=2)||(d[l2]>=21&&d[l2]-c[l2]>=2)) l2++;
cin>>s;
}
for(int j=0; j<=l1; j++) cout<<a[j]<<":"<<b[j]<<endl;
cout<<endl;
for(int j=0; j<=l2; j++) cout<<c[j]<<":"<<d[j]<<endl;
return 0;
}
@KARA_214 你那f从0开始 所以i应从0开始到tmp-1,还有我没看懂你的做法
by xujiacheng0312 @ 2024-08-08 16:24:53
且改了后还是错的
by KARA_214 @ 2024-08-10 16:59:36
@xujiacheng0312 谢谢