虫虫首页|资源下载|资源专辑|精品软件
登录|注册

您现在的位置是:虫虫下载站 > 资源下载 > 源码 > 运动会源代码

运动会源代码

  • 资源大小:21 K
  • 上传时间: 2016-12-28
  • 上传用户:150501
  • 资源积分:2 下载积分
  • 标      签: 源代码

资 源 简 介

  1. #include <malloc.h>      
  2. #include <stdio.h>      
  3. #include <stdlib.h>      
  4. #include <string.h>      
  5. #define NULL 0     
  6. #define MaxSize 30     
  7.    
  8. typedef struct athletestruct /*运动员*/    
  9. {    
  10.     char name[20];     
  11.     int score; /*分数*/    
  12.     int range; /**/    
  13.     int item; /*项目*/    
  14. }ATH;    
  15. typedef struct schoolstruct /*学校*/    
  16. {    
  17.     int count; /*编号*/    
  18.     int serial; /**/     
  19.     int menscore; /*男选手分数*/    
  20.     int womenscore; /*女选手分数*/    
  21.     int totalscore; /*总分*/    
  22.     ATH athlete[MaxSize]; /**/    
  23.     struct schoolstruct *next;     
  24. }SCH;    
  25.    
  26. int nsc,msp,wsp;     
  27. int ntsp;     
  28. int i,j;     
  29. int overgame;     
  30. int serial,range;     
  31. int n;     
  32. SCH *head,*pfirst,*psecond;     
  33. int *phead=NULL,*pafirst=NULL,*pasecond=NULL;    
  34. void create();    
  35.    
  36. void input ()    
  37. {    
  38.     char answer;     
  39.     head = (SCH *)malloc(sizeof(SCH)); /**/    
  40.     head->next = NULL;    
  41.     pfirst = head;     
  42.     answer = 'y';    
  43.     while ( answer == 'y' )    
  44.     {    
  45.     Is_Game_DoMain:    
  46.     printf("\nGET Top 5 when odd\nGET Top 3 when even");    
  47.     printf("\n输入运动项目序号 (x<=%d):",ntsp);    
  48.     scanf("%d",pafirst);    
  49.     overgame = *pafirst;    
  50.     if ( pafirst != phead )    
  51.     {    
  52.         for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ )    
  53.         {    
  54.             if ( overgame == *pasecond )    
  55.             {    
  56.                 printf("\n这个项目已经存在请选择其他的数字\n");    
  57.                 goto Is_Game_DoMain;    
  58.             }    
  59.         }    
  60.     }    
  61.     pafirst = pafirst + 1;    
  62.     if ( overgame > ntsp )    
  63.     {    
  64.         printf("\n项目不存在");    
  65.         printf("\n请重新输入");    
  66.         goto Is_Game_DoMain;    
  67.     }    
  68.     switch ( overgame%2 )    
  69.     {    
  70.     case 0: n = 3;break;    
  71.     case 1: n = 5;break;    
  72.     }    
  73.     for ( i = 1 ; i <= n ; i++ )    
  74.     {    
  75.     Is_Serial_DoMain:    
  76.     printf("\n输入序号 of the NO.%d (0<x<=%d): ",i,nsc);    
  77.        
  78.     scanf("%d",&serial);    
  79.     if ( serial > nsc )     
  80.     {    
  81.         printf("\n超过学校数目,请重新输入");    
  82.         goto Is_Serial_DoMain;    
  83.     }    
  84.     if ( head->next == NULL )     
  85.     {    
  86.         create();    
  87.     }    
  88.     psecond = head->next ;     
  89.     while ( psecond != NULL )     
  90.     {    
  91.         if ( psecond->serial == serial )    
  92.         {    
  93.             pfirst = psecond;    
  94.             pfirst->count = pfirst->count + 1;    
  95.             goto Store_Data;    
  96.         }    
  97.         else    
  98.         {    
  99.             psecond = psecond->next;    
  100.         }    
  101.     }    
  102.     create();    
  103.     Store_Data:    
  104.        
  105.     pfirst->athlete[pfirst->count].item = overgame;    
  106.     pfirst->athlete[pfirst->count].range = i;    
  107.     pfirst->serial = serial;    
  108.     printf("Input name:) : ");    
  109.        
  110.     scanf("%s",pfirst->athlete[pfirst->count].name);    
  111.     }    
  112.     printf("\n继续输入运动项目(y&n)?");    
  113.     answer = getchar();    
  114.     printf("\n");    
  115.     }    
  116. }    
  117.    
  118. void calculate() /**/    
  119. {    
  120.     pfirst = head->next;    
  121.     while ( pfirst->next != NULL )    
  122.     {    
  123.         for (i=1;i<=pfirst->count;i++)    
  124.         {    
  125.             if ( pfirst->athlete[i].item % 2 == 0 )     
  126.             {    
  127.                 switch (pfirst->athlete[i].range)    
  128.                 {    
  129.                 case 1:pfirst->athlete[i].score = 5;break;    
  130.                 case 2:pfirst->athlete[i].score = 3;break;    
  131.                 case 3:pfirst->athlete[i].score = 2;break;    
  132.                 }    
  133.             }    
  134.             else     
  135.             {    
  136.                 switch (pfirst->athlete[i].range)    
  137.                 {    
  138.                 case 1:pfirst->athlete[i].score = 7;break;    
  139.                 case 2:pfirst->athlete[i].score = 5;break;    
  140.                 case 3:pfirst->athlete[i].score = 3;break;    
  141.                 case 4:pfirst->athlete[i].score = 2;break;    
  142.                 case 5:pfirst->athlete[i].score = 1;break;    
  143.                 }    
  144.             }    
  145.             if ( pfirst->athlete[i].item <=msp )     
  146.             {    
  147.                 pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score;    
  148.             }    
  149.             else     
  150.             {    
  151.                 pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score;    
  152.             }    
  153.         }    
  154.         pfirst->totalscore = pfirst->menscore + pfirst->womenscore;    
  155.         pfirst = pfirst->next;    
  156.     }    
  157. }    
  158.    
  159. void output()    
  160. {    
  161.     pfirst = head->next;    
  162.     psecond = head->next;    
  163.     while ( pfirst->next != NULL )     
  164.     {    
  165.         // clrscr();     
  166.         printf("\n第%d号学校的结果成绩:",pfirst->serial);    
  167.         printf("\n\n项目的数目\t学校的名字\t分数");    
  168.         for (i=1;i<=ntsp;i++)     
  169.         {    
  170.             for (j=1;j<=pfirst->count;j++)     
  171.             {    
  172.                 if ( pfirst->athlete[j].item == i )    
  173.                 {    
  174.                        
  175.                        
  176.                     printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break;    
  177.                        
  178.                 }    
  179.             }    
  180.         }    
  181.         printf("\n\n\n\t\t\t\t\t\t按任意建 进入下一页");    
  182.         getchar();    
  183.         pfirst = pfirst->next;    
  184.     }    
  185. //  clrscr();     
  186.     printf("\n运动会结果:\n\n学校编号\t男运动员成绩\t女运动员成绩\t总分");    
  187.     pfirst = head->next;    
  188.     while ( pfirst->next != NULL )    
  189.     {    
  190.         printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore);    
  191.         pfirst = pfirst->next;    
  192.     }    
  193.     printf("\n\n\n\t\t\t\t\t\t\t按任意建结束");    
  194.     getchar();    
  195. }    
  196.    
  197. void create()    
  198. {    
  199.        
  200.     pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct));    
  201.     pfirst->next = head->next ;    
  202.     head->next = pfirst ;    
  203.        
  204.     pfirst->count = 1;    
  205.     pfirst->menscore = 0;    
  206.     pfirst->womenscore = 0;    
  207.     pfirst->totalscore = 0;    
  208. }    
  209. void Save()    
  210. {FILE *fp;    
  211. if((fp = fopen("school.dat","wb"))==NULL)    
  212. {printf("can't open school.dat\n");    
  213. fclose(fp);    
  214. return;    
  215. }    
  216. fwrite(pfirst,sizeof(SCH),10,fp);    
  217. fclose(fp);    
  218. printf("文件已经成功保存\n");    
  219. }    
  220.    
  221. void main()    
  222. {    
  223.     system("cls");    
  224.     printf("\n\t\t\t 运动会分数统计\n");    
  225.     printf("输入学校数目 (x>= 5):");    
  226.     scanf("%d",&nsc);     
  227.     printf("输入男选手的项目(x<=20):");    
  228.     scanf("%d",&msp);     
  229.     printf("输入女选手项目(<=20):");    
  230.     scanf("%d",&wsp);     
  231.     ntsp = msp + wsp;     
  232.        
  233.     phead = (int *)calloc(ntsp,sizeof(int));    
  234.     pafirst = phead;    
  235.     pasecond = phead;    
  236.     input();    
  237.     calculate();     
  238.     output();    
  239.     Save();    
  240. }     
  241.    
  242.    

相 关 资 源