#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define n 4
#define m 3
#define w 2
struct achievement //定義表示成績(jī)的結(jié)構(gòu)體
{int schoolnumber;//學(xué)校編號(hào)
char name[20]; //姓名
int mark; //分?jǐn)?shù)
int result;};
struct pro //表示項(xiàng)目的結(jié)構(gòu)體
{int tag;//項(xiàng)目編號(hào)
struct achievement ach[5];
int number;};
struct Node
{struct pro date;
struct Node *next;};
void ListInitiate(struct Node * *head) //初始化單鏈表
{
if((*head=(struct Node*)malloc(sizeof(struct Node)))==NULL) exit(1);
(*head)->next=NULL;
}
void main()
{
int i,j,t;
int x[n]={0};int y[n]={0};
struct Node *head;
struct Node *p;
struct Node *q;
ListInitiate(&head);
p=head;
for(i=0;i<m+w;i++) //輸入成績(jī)
{
j=i+1;
printf("請(qǐng)輸入第%d個(gè)項(xiàng)目的信息\n",j);
p->date.number=j;
printf("所取的名次數(shù)為:");
scanf("%d",&p->date.tag);
while(p->date.tag!=3&&p->date.tag!=5)
{printf("輸入有誤,請(qǐng)重新輸入!");
printf("所取的名次數(shù)為:");
scanf("%d",&p->date.tag);}
t=1;
while(t<=p->date.tag)
{
printf("第%d名的名字:",t);
scanf("%s",&p->date.ach[t-1].name);
printf("第%d名的學(xué)校:",t);
scanf("%d",&p->date.ach[t-1].schoolnumber);
printf("第%d名的分?jǐn)?shù):",t);
scanf("%d",&p->date.ach[t-1].mark);
p->date.ach[t-1].result=t;
t++;
}
q=(struct Node*)malloc(sizeof(struct Node)); //生成新結(jié)點(diǎn)
p->next=q;
p=q;
p->next=NULL;
}
for(i=0;i<n;i++) //產(chǎn)生成績(jī)單
{
j=i+1;
printf("學(xué)校%d成績(jī)單\n",j);
//t=1;
p=head;
do
{
t=1;
while(t<=p->date.tag)
{
if(p->date.ach[t-1].schoolnumber==j)
{
printf("獲獎(jiǎng)項(xiàng)目:%d ",p->date.number);
printf("名次:%d \n",p->date.ach[t-1].result);
printf("獲獎(jiǎng)人姓名:%s ",p->date.ach[t-1].name);
printf("所得分?jǐn)?shù):%d ",p->date.ach[t-1].mark);
if(p->date.number<=m)
x[i]=x[i]+p->date.ach[t-1].mark;
else
y[i]=y[i]+p->date.ach[t-1].mark;
}
t++;
}
p=p->next;
}while(p!=NULL);
printf("\n男子團(tuán)體總分:%d ",x[i]);
printf("女子團(tuán)體總分:%d \n",y[i]);
printf("\n團(tuán)體總分:%d\n",x[i]+y[i]);
}
}