⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhouhpfenshutongji.c

📁 本程序执行命令包括: 1)输入比赛数据 2)查询相关记录 3)显示各学校的成绩单 4)显示各校团体总分报表
💻 C
字号:


//包含的头文件有:
#include <malloc.h>              //分配size个字节的内存空间
#include <stdio.h>               //输入输出函数
#include <stdlib.h>              //动态存储分配函数或其他函数
#define NULL 0
#define MaxSize 30
//变量的定义一:
struct athletestruct             //参赛运动员
{
    char name[20];               //姓名
    int score;                   //得分成绩
    int range;                   //得分名次
    int item;                    //得分项目
};
struct schoolstruct              //参赛学校
{
    int count;                   //计算实际运动员个数
    int serial;                  //学校编号
    int menscore;                //男子团体总分
    int womenscore;              //女子团体总分
    int totalscore;              //团体总分
    struct athletestruct athlete[MaxSize];     //参赛运动员
    struct schoolstruct *next;                 //参赛学校
};
//变量的定义二:
int nsc,msp,wsp;                               //实际参赛学校个数,男子项目,女子项目
int ntsp;                                      //项目总数
int i,j;                                       //循环控制变量
int overgame;                                  //已结束的项目编号
int serial,range;                              //获奖的学校编号 & 获奖名次
int n;                                         //用来判断项目类型(奇&偶)
struct schoolstruct *head,*pfirst,*psecond;    //用于开辟存储区域
int *phead=NULL,*pafirst=NULL,*pasecond=NULL;  //用于项目数组指针
//A:输入模块
//   建立链表,然后存储数据。
 //建立链表
input ()
{
    char answer;                               //接受判断所有项目是否结束:'y'结束,'n'没结束
    head = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));
    head->next = NULL;
    pfirst = head;                             //工作指针
    answer = 'y';
    while ( answer == 'y' )
    {
Is_Game_DoMain:
        printf("\n奇数项目取前五名\n偶数项目取前三名");
        printf("\n请输入运动项目序号(<=%d):",ntsp);
        scanf("%d",pafirst);
        overgame = *pafirst;
        if ( pafirst != phead )
        {
            for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )
            {
                if ( overgame == *pasecond )
                {
                    printf("\n*此运动项目已经输过,请重新选其他项目序号!\n");
                    goto Is_Game_DoMain;
                }
            }
        }
        pafirst = pafirst + 1;
        if ( overgame > ntsp )
        {
            printf("\n没有这样的运动项目!");
            printf("\n请重新输入!"); 
            goto Is_Game_DoMain;
        }
        switch ( overgame%2 )
        {
            case 0: n = 3;break;
            case 1: n = 5;break;
        }
        for ( i = 1 ; i <= n ; i++ )
        {
Is_Serial_DoMain:
            printf("\n请输入第 %d名学校的编号(>0&<=%d): ",i,nsc);

            scanf("%d",&serial);
            if ( serial > nsc )                                             //判断是否存在该校
            {
                printf("\n编号超出学校总数!\n请重新输入!");
                goto Is_Serial_DoMain;
            }
            if ( head->next == NULL )                                       //建立第一个节点
            {
                create();
            }
            psecond = head->next ;                                          //遍历指针
            while ( psecond != NULL )                                       //遍历链表判断是否已存在该校
            {
                if ( psecond->serial == serial )
                {
                    pfirst = psecond;
                    pfirst->count = pfirst->count + 1;
                    goto Store_Data;
                }
                else
                {
                    psecond = psecond->next;
                }
            }
            create();
Store_Data:
//存储数据
            pfirst->athlete[pfirst->count].item = overgame;
            pfirst->athlete[pfirst->count].range = i;
            pfirst->serial = serial;
            printf("请输入名字(支持中文):  ");
            scanf("%s",pfirst->athlete[pfirst->count].name);
        }
        printf("\n是否是否继续输入运动项目?(y&n) ");
        answer = getch();
        printf("\n");
    }
}
//B:计算统计模块
//  通过遍历链表,将各参赛学校的成绩统计出来并存入结构成员中,来修改链表中的数据。
//计算
calculate()
{
    pfirst = head->next;
    while ( pfirst->next != NULL )
    {
        for (i=1;i<=pfirst->count;i++)
        {
            if ( pfirst->athlete[i].item % 2 == 0 )                     //偶数项目
            {
                switch (pfirst->athlete[i].range)
                {
                    case 1:pfirst->athlete[i].score = 5;break;
                    case 2:pfirst->athlete[i].score = 3;break;
                    case 3:pfirst->athlete[i].score = 2;break;
                }
            }
            else                                                        //奇数项目
            {
                switch (pfirst->athlete[i].range)
                {
                    case 1:pfirst->athlete[i].score = 7;break;
                    case 2:pfirst->athlete[i].score = 5;break;
                    case 3:pfirst->athlete[i].score = 3;break;
                    case 4:pfirst->athlete[i].score = 2;break;
                    case 5:pfirst->athlete[i].score = 1;break;
                }
            }
            if ( pfirst->athlete[i].item <=msp )                        //男子项目
            {
                pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;
            }
            else                                                        //女子项目
            {
                pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;
            }
        }
        pfirst->totalscore = pfirst->menscore + pfirst->womenscore;
        pfirst = pfirst->next;
    }
}
//C:输出模块
//   遍历链表,将calculate()模块中的数据输出。
//输出
output()
{
    pfirst = head->next;
    psecond = head->next;
    while ( pfirst->next != NULL )                                              //学校
    {
        clrscr();
        printf("\n 第%d名的运动项目学校得分成绩:",pfirst->serial);
        printf("\n\n项目编号\t学校名称\t得分");
        for (i=1;i<=ntsp;i++)                                                   //项目
        {
            for (j=1;j<=pfirst->count;j++)                                      //运动员
            {
                if ( pfirst->athlete[j].item == i )
                {
                    switch (pfirst->athlete[j].range)
                    {
               case1:printf("\n    %d\t\t%s          %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;
case2:printf("\n     %d\t\t\t\t%s     %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;
case3:printf("\n     %d\t\t\t\t\t\t%s     %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;
case4:printf("\n     %d\t\t\t\t\t\t\t\t%s     %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;
case5:printf("\n     %d\t\t\t\t\t\t\t\t\t\t%s     %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;
                    }
                }
            }
        }
        printf("\n\n\n\t\t\t\t\t\t按任意键进入下一页!");
        getch();
        pfirst = pfirst->next;
    }
    clrscr();
    printf("\n比赛情况结果显示:\n\n学校编号\t男子得分\t女子得分\t总  分");
    pfirst = head->next;
    while ( pfirst->next != NULL )
    {
        printf("\n    %d\t\t    %d\t\t    %d\t\t  %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);
        pfirst = pfirst->next;
    }
    printf("\n\n\n\t\t\t\t\t\t\t按任意键结束!"); 
    getch();
}
//另外再一个建立链表。
create()
{
    //前插建链表
    pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));
    pfirst->next = head->next ;
    head->next = pfirst ;
    //节点的初始化
    pfirst->count = 1;
    pfirst->menscore = 0;
    pfirst->womenscore = 0;
    pfirst->totalscore = 0;
}
//主函数:
main()
{
    system("cls");
    printf("\n\t\t\t    运动会分数统计");
    printf("\n\t\t\t  http://www.virz.net\n\n");
    printf("请输入参赛学校总数(>= 5): ");
    scanf("%d",&nsc);     //读入参赛学校数
    printf("请输入男子项目总数(<=20): ");
    scanf("%d",&msp);     //读入男子项目
    printf("请输入女子项目总数(<=20): ");
    scanf("%d",&wsp);     //读入女子项目
    ntsp = msp + wsp;                                              //运动总项目
//以下段,用来解决特定问题。
    phead = calloc(ntsp,sizeof(int));
    pafirst = phead;
    pasecond = phead;
    input();
    calculate();                                                   //计算
    output();
}


 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -