数据结构习题集之运动会分数统计

运动会分数统计

#include 
#include 
#include 
typedef struct Score{
    char AthleteName [20];
    char SchoolName [20];
    int SchoolCode;
    int Rank;
    char Achievement [10];
}Score;

typedef struct Match{
    int MatchCode;
    char  MatchName[10];
    int Top;
    Score *RankList;
}Match,*Event;

typedef struct Record{
    int MatchCode;
    char  MatchName[10];
    int Rank;
    char Achievement [10];
    char AthleteName [20];
    int GetScore;
}Record;

typedef struct School{
   char SchoolName [20];
   int num;
   int ptr;
   Record *RecordList;
}School,*SchoolSheet;

typedef struct Team{
    int SchoolCode;
    char SchoolName [20];
    int ManTotal;
    int WomanTotal;
    int  TeamTotal;
}Team,*All;

int n,m,w,t;
Event A;
SchoolSheet  B;
All C;
int ScoreList [8]={5,3,2,7,5,3,2,1};

void Start()
{
    printf("<<<<<<<<---------------------------------------------------->>>>>>>>>>\n");
    printf("              欢迎使用运动会分数统计系统                    \n");
    printf("<<<<<<<<---------------------------------------------------->>>>>>>>>>\n");
    return;
}

void Function()
{
    printf("\n\n<<<<<<<<<<<<----功能选择---->>>>>>>>>>>>>>>\n\n");
    printf("-------------1.登录初始化\n");
    printf("-------------2.清零\n");
    printf("-------------3.录入各项比赛成绩\n");
    printf("-------------4.产生学校成绩单\n");
    printf("-------------5.产生团体总分报表\n");
    printf("-------------6.结果显示\n");
    printf("-------------7.返回主界面\n");
    printf("-------------0.退出系统\n\n\n");
    return;
}
void  login()
{
    char Passpord [12]="yzc5201314";
    printf("请输入密码: \n");
    char Key[12];
    scanf("%s",Key);
    while(1){
         if(strcmp(Passpord,Key)==0)
             break;
         else
         {
              printf("请再次输入密码:\n");
              scanf("%s",Key);
         }
    }
    printf("参加运动会的学校个数:  ");
    scanf("%d",&n);
    printf("运动会的男子项目个数:  ");
    scanf("%d",&m);
    printf("运动会的女子项目个数:  ");
    scanf("%d",&w);
    A=(Event)malloc((w+m)*sizeof(Match));
    B=(SchoolSheet)malloc(n*sizeof(School));
    C=(All)malloc(n*sizeof(Team));
    if(!A)
       exit(1);
     if(!B)
       exit(1);
    if(!C)
       exit(1);
    return;
}
void Clear()
{
    for(int i=0;inum=0;
        (B+i)->ptr=0;
        (B+i)->RecordList=NULL;
        (C+i)->SchoolCode=0;
        (C+i)->ManTotal=0;
        (C+i)->WomanTotal=0;
        (C+i)->TeamTotal=0;
    }
    for(int j=0;j<(m+w);j++){
        (A+j)->Top=0;
        (A+j)->MatchCode=0;
        (A+j)->RankList=NULL;
    }
    return;
}

void Input(){
    int num=0;
    for(int i=0;i<(m+w);i++)
    {
        (A+i)->MatchCode=i+1;
        scanf("%d%s",&(A+i)->Top,(A+i)->MatchName);
        num=(A+i)->Top;
        (A+i)->RankList=(Score*)malloc(num*sizeof(Score));
        Score *R=(A+i)->RankList;
        for(int j=0;jRank=j+1;
            scanf("%s", (R+j)->AthleteName);
            scanf("%s", (R+j)->SchoolName);
            scanf("%d",&(R+j)->SchoolCode);
            (B+(R+j)->SchoolCode-1)->num++;
            scanf("%s", (R+j)->Achievement);
        }
    }
    return;
}
void SchoolScoreSheet()
{
    for(int j=0;jnum;
        (B+j)->RecordList=(Record *)malloc( c*sizeof(Record));
    }
    int num=0;
    for(int i=0;i<(m+w);i++)
    {
         Score *R=(A+i)->RankList;
         num=(A+i)->Top;
         for(int j=0;jSchoolCode-1;
              strcpy( (B+k)->SchoolName,(R+j)->SchoolName);
              h=(B+k)->ptr;
              Record *L=(B+k)->RecordList;
              (L+h)->MatchCode=i+1;
              (L+h)->Rank=(R+j)->Rank;
              strcpy( (L+h)->MatchName,(A+i)->MatchName);
              strcpy( (L+h)->AthleteName,(R+j)->AthleteName);
              strcpy( (L+h)->Achievement,(R+j)->Achievement);
              if((A+i)->Top!=3)
                 (L+h)->GetScore=ScoreList[(R+j)->Rank+2];
              else
                 (L+h)->GetScore=ScoreList[(R+j)->Rank-1];
              (B+k)->ptr++;
         }
    }
    return;
}

void TeamScoreSheet()
{
         for(int i=0;iSchoolCode=i+1;
             strcpy( (C+i)->SchoolName,(B+i)->SchoolName);
             Record * L=(B+i)->RecordList;
             for(int j=0;j<(B+i)->num;j++)
             {
                 if((L+j)->MatchCode<=m)
                    (C+i)->ManTotal=(C+i)->ManTotal+(L+j)->GetScore;
                 else
                    (C+i)->WomanTotal= (C+i)->WomanTotal+(L+j)->GetScore;
             }
             (C+i)->TeamTotal=(C+i)->ManTotal+(C+i)->WomanTotal;
         }
         return;
}

void Show(){
    for(int i=0;iSchoolName);
        printf("\n\t项目号\t项目名\t姓名\t名次\t成绩\t   得分\n");
        int k=(B+i)->num;
        Record *L=(B+i)->RecordList;
        for(int j=0;jMatchCode,(L+j)->MatchName,(L+j)->AthleteName,(L+j)->Rank,(L+j)->Achievement,  (L+j)->GetScore);
        }
    }
    printf("\n\n团体总分报表:\n");
    printf("\n\t校号\t学校名称    \t男子团体总分\t女子团体总分\t团体总分\n");
    for(int i=0;iSchoolCode,(C+i)->SchoolName,(C+i)->ManTotal, (C+i)->WomanTotal, (C+i)->TeamTotal);
    }
    return;
}
void logoff()                       //退出系统
{
     printf("\n\t\t>>>>>>>>Welcome back!!<<<<<<<<<\n");
     exit(0);
}

void Home()
{
    Function();
    while(1){
    printf("请输入选择的功能:");
    scanf("%d",&t);
    while(t!=0&&t!=1&&t!=2&&t!=3&&t!=4&&t!=5&&t!=6&&t!=7)
   {
   printf("输入有误,请重新选择:");
   scanf("%d",&t);
   }
   switch(t)
   {
   case 1:    login();break;
   case 2:    Clear();break;
   case 3:    Input();break;
   case 4:    SchoolScoreSheet();break;
   case 5:    TeamScoreSheet();break;
   case 6:    Show();break;
   case 7:    Home();break;
   case 0:    logoff();break;
   }
}
return;
}
int main()
{
    system("Color 1e");
    Start();
    Home();
    return 0;
}

数据结构习题集之运动会分数统计_第1张图片
数据结构习题集之运动会分数统计_第2张图片
数据结构习题集之运动会分数统计_第3张图片

你可能感兴趣的:(数据结构与算法)