69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
void main()
{
int i,j; /*定义每一局A,B的分数,*/
int Ps=1; /*比赛的盘数*/
int score_A,score_B;
printf("请输入第一局比赛A,B的分数:\n");
scanf("%d %d",i,j); /*给出第一局A,B的最终分数*/
while(i>j)
{score_A++;printf("%d% d",i,j);} /*给A加一分,输出A,B的比分*/
while(i<j)
{score_B++;printf("%d %d",i,j);} /*给B加一分,输出A,B的比分*/
Ps++;
}
int main()
{
while (比赛是否结束())
{
while (一局是否结束())
{
取得得分方();
为得分方加分();
输出得分信息();
}
}
输出最终结果();
}
bool 比赛是否结束()
{
if (某一方赢了3局)
返回true;
else
返回false;
}
bool 一局是否结束()
{
else if (有一方得分不小于11 并且 双方得分之差大于1)
返回true;
else
返回false;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#define MATCH_NUM 5
#define A_WIN 0
#define B_WIN 1
#define MATCH_POINT 11
typedef struct tagSetRecord
{
int result; /*本盘的结局0---A win 1------B win*/
int score_a; /*本盘选手A的分数*/
int score_b; /*本盘选手B的分数*/
}SetRecord;
typedef struct tagGameRecord
{
int result; /*比赛的结局0---A win 1------B win*/
SetRecord sets[MATCH_NUM+1]; /*每局比赛记录信息*/
}GameRecord;
GameRecord g_stRecord; /*全局记录信息*/
int g_ulSet = 0; /*打的局数*/
int g_ulSet_awin = 0; /*a赢的局数*/
int g_ulSet_bwin = 0; /*b赢的局数*/
void init_game(void)
{
int i;
g_ulSet = 0;
memset(&g_stRecord,0,sizeof(GameRecord));
g_stRecord.result = 0xffffffff;
for (i=0;i<=MATCH_NUM;i++)
{
g_stRecord.sets[i].result = 0xffffffff;
}
return;
}
void game_set(char match)
{
g_ulSet++;
while(g_stRecord.sets[g_ulSet].result!=A_WIN && g_stRecord.sets[g_ulSet].result!=B_WIN)
{
printf("请输入比分(a or b):");
scanf("%c",&match);
fflush(stdin);
switch (match)
{
case 'a':
g_stRecord.sets[g_ulSet].score_a++;
break;
case 'b':
g_stRecord.sets[g_ulSet].score_b++;
break;
default:
break;
}
if ((g_stRecord.sets[g_ulSet].score_a==MATCH_POINT)
&&(2<=(g_stRecord.sets[g_ulSet].score_a-g_stRecord.sets[g_ulSet].score_b)))
{
g_stRecord.sets[g_ulSet].result = A_WIN;
g_ulSet_awin++;
}
else if ((g_stRecord.sets[g_ulSet].score_b==MATCH_POINT)
&&(2<=(g_stRecord.sets[g_ulSet].score_b-g_stRecord.sets[g_ulSet].score_a)))
{
g_stRecord.sets[g_ulSet].result = B_WIN;
g_ulSet_bwin++;
}
else if((10<=g_stRecord.sets[g_ulSet].score_a)
&&(10<=g_stRecord.sets[g_ulSet].score_b))
{
if (2<=(g_stRecord.sets[g_ulSet].score_a-g_stRecord.sets[g_ulSet].score_b))
{
g_stRecord.sets[g_ulSet].result = A_WIN;
g_ulSet_awin++;
}
else if (2<=(g_stRecord.sets[g_ulSet].score_b-g_stRecord.sets[g_ulSet].score_a))
{
g_stRecord.sets[g_ulSet].result = B_WIN;
g_ulSet_bwin++;
}
}
}
return;
}
void display_result(GameRecord *pstRecord)
{
int i;
printf("\n\r the match result is %d",pstRecord->result);
for (i=1;i<=g_ulSet;i++)
{
printf("\n\r the set result is %d",g_stRecord.sets[i].result);
printf("\n\r the a score is %d",g_stRecord.sets[i].score_a);
printf("\n\r the b score is %d",g_stRecord.sets[i].score_b);
}
return;
}
void main()
{
char match = 0;
init_game();
while (g_stRecord.result!=A_WIN&&g_stRecord.result!=B_WIN)
{
game_set(match);
if(g_ulSet_awin==3)
g_stRecord.result = A_WIN;
else if(g_ulSet_bwin==3)
g_stRecord.result = B_WIN;
}
display_result(&g_stRecord);
system("pause");
}
void init_game(struct Game * p_game)
{
int s;
p_game->result = -1; /*表示还没有胜者*/
p_game->set_left=NR_SETS; /*一盘都还没有打*/
for(s = 0; s < NR_SETS; s++) {
p_game->sets[s]->result_set = -1;
p_game->sets[s]->win_point = 11;
p_game->sets[s]->cur_score_a = 0;
p_game->sets[s]->cur_score_b = 0;
}
}