乒乓球问题 c语言 90分 没通过 知道答案者留下

#include <stdio.h>


#define MAX_NUM 400000


int main(void)
{
    char Score[MAX_NUM] = {0};//每一次的分数
int Count = 0;//胜负一共的数
int Win = 0;//胜次数
int Lose = 0;//输的次数
char Temp[MAX_NUM] = {0};
char ch;
int Index = 0;


//获取输入字符
while(1)
{
ch = getchar();
//
if(ch == 'E')
{
break;
}
else if(ch == 'W' || ch == 'L')
{
Score[Count++] = ch;
}
}


//11分一局 计算并输出
while( Index <= Count)
{
//计算本局比分 有一方达到11分并且分差大于2分 或者至少一方分数大于11并且分差大于两分
while( Index < Count)
{
if(Score[Index] == 'W')
{
Win++;
Index++;
}
else if(Score[Index] == 'L')
{
Lose++;
Index++;
}


//判断输赢
if(Win == 11 && Lose < 10)
{
break;
}
else if(Lose == 11 && Win < 10)
{
break;
}
else if( Win > 11 && Win - Lose > 1 )
{
break;
}
else if( Lose > 11 && Lose - Win > 1 )
{
break;
}
}
//输出本局结果
printf("%d:%d\n", Win,Lose);
if( Win == 0 &&  Lose == 0 || Index == Count)
{
Win = Lose = 0;
break;
}
Win = Lose = 0;
}


//
Index = 0;
printf("\n");


//21分一局 计算并输出
while( Index <= Count)
{
//计算本局比分 有一方达到21分并且分差大于2分 或者至少一方分数大于21并且分差大于两分
while( Index < Count)
{
if(Score[Index] == 'W')
{
Win++;
Index++;
}
else if(Score[Index] == 'L')
{
Lose++;
Index++;
}


//判断输赢
if(Win == 21 && Lose < 20)
{
break;
}
else if(Lose == 21 && Win < 20)
{
break;
}
else if( Win > 21 && Win - Lose > 1 )
{
break;
}
else if( Lose > 21 && Lose - Win > 1 )
{
break;
}
}
//输出本局结果
printf("%d:%d\n", Win,Lose);
if( Win == 0 &&  Lose == 0 || Index == Count)
{
Win = Lose = 0;
break;
}
Win = Lose = 0;
}


//while(1);
return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值