jiangsm @ 2024-08-12 19:36:04
4个WA6个RE,本地测试输出不出来
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a;
int player1=0,player2=0;
for(int i=0;;i++)
{
getline(cin,a);
if(a[i]=='E')
{
break;
}
}
int l=a.length();
for(int i=0;i<=l-1;i++)
{
if(a[i]=='W')
{
player1++;
}
else if(a[i]=='L')
{
player2++;
}
if((abs(player1-player2)>=2)&&((player1>=11)||(player2>=11)))
{
cout<<player1<<":"<<player2<<endl;
player1=0;
player2=0;
}
}
for(int i=0;i<=l-1;i++)
{
if(a[i]=='W')
{
player1++;
}
else if(a[i]=='L')
{
player2++;
}
if((abs(player1-player2)>=2)&&((player1>=21)||(player2>=21)))
{
cout<<player1<<":"<<player2<<endl;
}
}
}
by eggy_LIKE @ 2024-08-12 19:56:43
你可能是因为数据或空间溢出导致的
by LiujunjiaNC @ 2024-08-12 20:03:40
@jiangsm
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a;
char c;
int player1=0,player2=0;
while(cin>>c&&c!='E'){
a+=c;
}
int l=a.length();
for(int i=0;i<=l-1;i++)
{
if(a[i]=='W')
{
player1++;
}
else if(a[i]=='L')
{
player2++;
}
if((abs(player1-player2)>=2)&&((player1>=11)||(player2>=11)))
{
cout<<player1<<":"<<player2<<endl;
player1=0;
player2=0;
}
}
cout<<player1<<":"<<player2<<endl<<endl;
player1=0;
player2=0;
for(int i=0;i<=l-1;i++)
{
if(a[i]=='W')
{
player1++;
}
else if(a[i]=='L')
{
player2++;
}
if((abs(player1-player2)>=2)&&((player1>=21)||(player2>=21)))
{
cout<<player1<<":"<<player2<<endl;
player1=0;
player2=0;
}
}
cout<<player1<<":"<<player2<<endl<<endl;
}
by jiangsm @ 2024-08-13 18:34:36
@LiujunjiaNC谢谢大佬,已AC