Emmmmmmmmm,这个题如果你对乒乓球制度不了解就很坑。。。。
1、以11分制为例,赢则必须要两者分差大于等于2且赢的一方要至少有11分,就是说赢的不是一定就恰好11分的,有可能此时,12分,13分。。。。
2、还有就是0:0也要输出
#include<bits/stdc++.h>
using namespace std;
//int _max=-0x7fffffff;
typedef struct node
{
int X;
int Y;
}node;//输出即为X:Y
node A[10000];
node B[10000];
int _count1=0;
int _count2=0;
int main()
{
char S[63000];
int score1=0;
int score2=0;
int _score1=0;
int _score2=0;
int i;
while(scanf("%c",&S[i])&&S[i]!='E')
{
if(S[i]=='W')
{
score1++;
_score1++;
}
if(S[i]=='L')
{
score2++;
_score2++;
}
if(abs(score1-score2)>=2&&(score1>=11||score2>=11)) //if(abs(score1-score2)>=2&&(score1==11||score2==11))
{
A[_count1].X=score1;
A[_count1++].Y=score2;
score1=0;
score2=0;
}
if(abs(_score1-_score2)>=2&&(_score1>=21||_score2>=21))
{
B[_count2].X=_score1;
B[_count2++].Y=_score2;
_score1=0;
_score2=0;
}
i++;
}
for(int i=0;i<_count1;i++)
printf("%d:%d\n",A[i].X,A[i].Y);
//if(score1!=0||score2!=0)
printf("%d:%d\n",score1,score2);
printf("\n");
for(int i=0;i<_count2;i++)
printf("%d:%d\n",B[i].X,B[i].Y);
//if(_score1!=0||_score2!=0)
printf("%d:%d\n",_score1,_score2);
return 0;
}
第二个:
#include<bits/stdc++.h>
using namespace std;
//int _max=-0x7fffffff;
typedef struct node
{
int X;
int Y;
}node;//输出即为X:Y
node A[10000];
node B[10000];
int _count1=0;
int _count2=0;
int main()
{
char S[30];
int score1=0;
int score2=0;
int _score1=0;
int _score2=0;
int FLAG=1;
while(FLAG&&scanf("%s",S)!=EOF) //while(scanf("%s",S)&&FLAG)
{
int len=strlen(S);
for(int i=0;i<len;i++)
{
if(S[i]=='W')
{
score1++;
_score1++;
}
if(S[i]=='L')
{
score2++;
_score2++;
}
if(abs(score1-score2)>=2&&(score1>=11||score2>=11)) //之前写的错的:if(abs(score1-score2)>=2&&(score1==11||score2==11))
{
A[_count1].X=score1;
A[_count1++].Y=score2;
score1=0;
score2=0;
}
if(abs(_score1-_score2)>=2&&(_score1>=21||_score2>=21))
{
B[_count2].X=_score1;
B[_count2++].Y=_score2;
_score1=0;
_score2=0;
}
if(S[i]=='E')
{
FLAG=0;
break;
}
}
}
for(int i=0;i<_count1;i++)
printf("%d:%d\n",A[i].X,A[i].Y);
//if(score1!=0||score2!=0)
printf("%d:%d\n",score1,score2);
printf("\n");
for(int i=0;i<_count2;i++)
printf("%d:%d\n",B[i].X,B[i].Y);
//if(_score1!=0||_score2!=0)
printf("%d:%d\n",_score1,_score2);
return 0;
}