运动会分数统计
写的比较繁琐 希望同仁给点意见!#include <stdio.h>
#include <malloc.h>
#define null 0
#define error 0
#define ok 1
#define maxsize 100
typedef struct geren
{char xingming[20]; /*姓名*/
int item; /*项目*/
int mingci; /*名次*/
int score; /*分数*/
}ath;
typedef struct xuexiao
{int count; /*学校编号*/
int serial; /*学校共得奖次数*/
int manscore; /*男子总分*/
int womanscore; /*女子总分*/
int totalscore; /*团体总分*/
geren abc[maxsize];
xuexiao *next;} lnode;
int xsm,naz,won;
int zxm;
int i,j;
int item;
int overgame;
int n;
int m;
int xuebian;
lnode *xhead,*xzhong,*xwei;
int *tou=null,*zhong=null,*wei=null;
void main()
{void input();
void creat();
void shuru();
void fenshu();
void shuchu();
int x=1,y=1;
while(x==1)
{printf("请输入男子项目数并<=30:\n");
scanf("%d",&naz);
if(naz>20)
{printf("输入男子项目数>30请重新输入:\n\n");continue;}
x=0;}
while(y==1)
{printf("请输入女子项目数并<=20:\n");
scanf("%d",&won);
if(won>20)
{printf("输入女子项目数>20请重新输入:\n\n");continue;}
y=0;}
zxm=naz+won;
tou=(int*)malloc(zxm*sizeof(int));
zhong=tou;
wei=tou;
input();
fenshu();
shuchu();
}
void input()
{void creat();
void shuru();
xsm=20;
lnode *p;
xhead=(lnode*)malloc(sizeof(lnode));
xhead->next=null;
xzhong=xhead;
int m=1,h=1;
char any;
any='y';
while(any=='y')
{m=1;
while(m==1)
{printf("请输入比赛项目:\n");
scanf("%d",wei);
overgame=*wei;
if(overgame>zxm) {printf("输入项目编号已经超出总项目请重新输入:\n\n");continue;}
for(zhong=tou;zhong<wei;zhong++)
{if(*zhong==overgame) break;}
if(*zhong==overgame&&zhong!=wei) {printf("已经重复输入项目编号请重新输入:\n\n");continue;}
wei++;
m=0;
}
switch(overgame%2)
{case 0: n=3; break;
case 1: n=5; break;
}
for(i=1;i<=n;i++)
{h=1;
printf("第%d项目第%d名部分:\n",overgame,i);
printf("请输入学校编号:\n");
scanf("%d",&xuebian);
if(xuebian>xsm||xuebian<=0)
{i--;printf("请输入学校编号>总学校数重新输入:\n\n");continue;}
if(xhead->next==null)
{creat();shuru();h=0;}
if(h==1)
{for(p=xhead->next;p!=null;p=p->next)
if(p->count==xuebian)
{xzhong=p;shuru();h=0;break;}}
if(h==1)
{creat();shuru();}
}
printf("是否继续输入项目?\n");
scanf("%s",&any);}
}
void creat()
{
xwei=(lnode*)malloc(sizeof(lnode));
xwei->next=null;
xzhong->next=xwei;
xzhong=xzhong->next;
xzhong->serial=0;
xzhong->manscore=0;
xzhong->womanscore=0;
xzhong->totalscore=0;}
void shuru()
{xzhong->count=xuebian;
xzhong->serial+=1;
printf("请输入第%d项目第%d名得奖姓名\n",overgame,i);
scanf("%s",xzhong->abc[xzhong->serial].xingming);
xzhong->abc[xzhong->serial].item=overgame;
xzhong->abc[xzhong->serial].mingci=i;
xzhong=xwei;
}
void fenshu()
{
for(xzhong=xhead->next;xzhong!=null;xzhong=xzhong->next)
{ for(i=1;i<=xzhong->serial;i++)
{if(xzhong->abc[i].item%2==0)
switch(xzhong->abc[i].mingci)
{case 1:xzhong->abc[i].score=5;break;
case 2:xzhong->abc[i].score=3;break;
case 3:xzhong->abc[i].score=1;break;}
else
switch(xzhong->abc[i].mingci)
{case 1:xzhong->abc[i].score=7;break;
case 2:xzhong->abc[i].score=5;break;
case 3:xzhong->abc[i].score=3;break;
case 4:xzhong->abc[i].score=2;break;
case 5:xzhong->abc[i].score=1;break;}
if(xzhong->abc[i].item<=naz)
xzhong->manscore+=xzhong->abc[i].score;
else
xzhong->womanscore+=xzhong->abc[i].score;}
xzhong->totalscore=xzhong->manscore+xzhong->womanscore;}}
void shuchu()
{for(xzhong=xhead->next;xzhong!=null;xzhong=xzhong->next)
{
printf("%d学校共有%d名运动员得奖:\n\n",xzhong->count,xzhong->serial);
for(i=1;i<=xzhong->serial;i++)
printf("%d学校%s同学获得%d项目的第%d名\n\n",xzhong->count,xzhong->abc[i].xingming,xzhong->abc[i].item,xzhong->abc[i].mingci);
printf("%d学校男子项目共获得%d分\n",xzhong->count,xzhong->manscore);
printf("%d学校女子项目共获得%d分\n",xzhong->count,xzhong->womanscore);
printf("%d学校团体项目共获得%d分\n",xzhong->count,xzhong->totalscore);
}
}