/*********************************************************************************
51. 微型蓝球赛. 甲,乙两队进行蓝球比赛,结果甲队以S:T 获胜.(T<S<=10, S,T
由键盘输入). 比赛中, 甲队得分始终领先(严格大于乙队). 规定以任何方式进一
球都只得一分. 编程序打印该比赛的每一种可能的不同的得分过程, 以及所有不同
过程的总数.
********************************************************************************/
#include <stdio.h>
#define N 10
//比分
typedef struct
{
int s;
int t;
}Score;
//计数器
int counter = 0;
//比分过程
Score sc[2*N]={{0,0}};
//打印比赛过程
void print_match_proc(int k)
{
int i;
for(i=0; i<=k; i++)
{
printf("%d---%d/n",sc[i].s,sc[i].t);
}
printf("---------------Proc%d--------------/n",++counter);
}
//比赛
void match(int S, int T, int k)
{
if(S>T)
{
sc[k].s = S;
sc[k].t = T;
if(S == N)//比赛结束
{
print_match_proc(k);
//getchar();
}
else
{
match(S+1,T,k+1);
match(S,T+1,k+1);
}
}
}
//main
void main()
{
match(1,0,1);
}
练习51
最新推荐文章于 2021-01-14 19:27:39 发布