主题:各位高手救命啊!帮帮小女子吧,只是小问题而已啊!
smlirly
[专家分:0] 发布于 2005-12-27 13:38:00
运动会分数统计
任务:参加运动会有n个学校,学校编号为1`````n。比赛分成m个男子项目,和w个女子项目。项目编号为男子1````m,女子为1`````m+w。不同的项目取前五名或前三名积分;取前五名的积分分别为7,5,3,2,1。前三名的积分分别为:5,3,2;哪些取前五名或前三名由学生自己设定。(m〈=20,n〈=20)
功能要求:1,可以输入各个项目的前三名或前五名的成绩;
2,能统计个学校总分;
3,可以按学校编号,学校总分,男女团体总分排序输出;
4,可以按学校编号查询学校某个项目的情况;可以按项目编号查询取得前三名或前五名的学校。
规定:输入数据形式和范围:20以内的整数(如果做得更好可以输入学校的名称,运动项目的名称)
输出形式:有中文提示,各学校分数为整形。
界面要求:有合理的提示,每个功能可以设立菜单,根据提示,可以完成相关的功能要求。
设计要求:说明每个部分的算法设计,说明每个程序中使用的存储结构设计。 各个算法实现的源程序,对每个题目要有相应的源程序。源程序要按照写程序的规则来编写。
回复列表 (共2个回复)
沙发
青竹轩主 [专家分:0] 发布于 2006-05-30 13:39:00
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define LEN1 sizeof(struct Program)
#define LEN2 sizeof(struct Player)
#define OK 1
#define ERROR 0
#define NULL 0
/***一个代表学校的结构体类型:学校编号,本校男子总分,本校女子总分********/
typedef struct School
{
int sch_num;
int sch_men_total;
int sch_women_total;
struct School *next;
}School,*Sch_List;
/***一个代表运动员的结构体类型:******/
typedef struct Player
{
int Pla_num; /*运动员号码*/
int Pla_sex; /*运动员性别*/
int Pla_school; /*运动员学校编号*/
int Pla_program; /*运动员项目编号*/
int Pla_mark; /*运动员取得比赛成绩*/
int Pla_point; /*运动员得分*/
struct Player *next;
}Player,*Pla_List;
/***一个代表项目的结构体类型:**************/
typedef struct Program
{
int Pro_num; /*项目编号*/
Pla_List MenHead; /*参加本项目的男运动员链表*/
Pla_List WomenHead; /*参加本项目的女运动员链表*/
struct Program *next;
}Program,*Pro_List;
/*********************************************/
Pla_List creat_playerlist(int Pro_num,int Pla_sex)
{
Pla_List head,p1,p2;
head=p1=p2=(Pla_List)malloc(LEN2);
head->next=NULL;
/*******建立头结点*****/
p1=(Pla_List)malloc(LEN2);
printf("input Player Number:\n");
scanf("%d",&p1->Pla_num);
printf("input Player school num:\n");
scanf("%d",&p1->Pla_school);
printf("input Player mark:\n");
scanf("%d",&p1->Pla_mark);
p1->Pla_program=Pro_num;
p1->Pla_sex=Pla_sex;
/********建立第一个数据结点********/
while(p1->Pla_num!=0)
{
p2->next=p1;
p2=p1;
p1=(Pla_List)malloc(LEN2);
printf("input Player Number:\n");
scanf("%d",&p1->Pla_num);
printf("input Player school num:\n");
scanf("%d",&p1->Pla_school);
printf("input Player mark:\n");
scanf("%d",&p1->Pla_mark);
p1->Pla_program=Pro_num;
p1->Pla_sex=Pla_sex;
}
p2->next=NULL;
/****陆续建立新的数据结点,插入单链表,直到建立系数为零的结点为止********/
return(head);
}
/*********把运动员链表调整为按MARK递降排列,采取选择法排序**************/
Pla_List order_playerlist(Pla_List head,int a)
{
Pla_List p1,p2;
Player temp;
p1=head->next;
for(;p1->next!=NULL;p1=p1->next)
{
for(p2=p1->next;p2!=NULL;p2=p2->next)
{
if(p2->Pla_mark>p1->Pla_mark)
{
temp.Pla_num=p1->Pla_num;
p1->Pla_num=p2->Pla_num;
p2->Pla_num=temp.Pla_num;
temp.Pla_sex=p1->Pla_sex;
p1->Pla_sex=p2->Pla_sex;
p2->Pla_sex=temp.Pla_sex;
temp.Pla_school=p1->Pla_school;
p1->Pla_school=p2->Pla_school;
p2->Pla_school=temp.Pla_school;
temp.Pla_program=p1->Pla_program;
p1->Pla_program=p2->Pla_program;
p2->Pla_program=temp.Pla_program;
temp.Pla_mark=p1->Pla_mark;
p1->Pla_mark=p2->Pla_mark;
p2->Pla_mark=temp.Pla_mark;
}
}
}
/****下面根据取得的名次写入得分POINT********/
if(a%2==1)
{
p1=head->next;
if(p1!=NULL)
{
p1->Pla_point=7;
p1=p1->next;
if(p1!=NULL)
{
p1->Pla_point=5;
p1=p1->next;
if(p1!=NULL)
{
p1->Pla_point=3;
p1=p1->next; p1->Pla_point=2;
if(p1!=NULL)
{
p1->Pla_point=2;
p1=p1->next; p1->Pla_point=1;
if(p1!=NULL)
{
p1->Pla_point=1;
p1=p1->next;
}
}
}
}
}
for(;p1!=NULL;p1=p1->next)
{
p1->Pla_point=0;
}
}
else
{
p1=head->next;
if(p1!=NULL)
{
p1->Pla_point=5;
p1=p1->next;
if(p1!=NULL)
{
p1->Pla_point=3;
p1=p1->next;
if(p1!=NULL)
{
p1->Pla_point=2;
p1=p1->next;
}
}
}
for(;p1!=NULL;p1=p1->next)
{
p1->Pla_point=0;
}
}
return (head);
}
/**********************************************/
Pro_List creat_programlist(void)
{
int sex;
Pro_List head,p1,p2;
head=p1=p2=(Pro_List)malloc(LEN1);
head->next=NULL;
/*******建立头结点*****/
/********建立第一个项目数据结点********/
p1=(Pro_List)malloc(LEN1);
printf("input Program number:\n");
scanf("%d",&p1->Pro_num);
printf("input info of men player:\n");
sex=1;
p1->MenHead=creat_playerlist(p1->Pro_num,sex); /***建立这个项目的运动员链表*****/
p1->MenHead=order_playerlist(p1->MenHead,p1->Pro_num); /***ORDER函数的目的有二,排序并且根据项目编号在运动员链表中写入得分POINT***/
printf("input info of women player:\n");
sex=2;
p1->WomenHead=creat_playerlist(p1->Pro_num,sex);
p1->WomenHead=order_playerlist(p1->WomenHead,p1->Pro_num);
while(p1->Pro_num!=0)
{
p2->next=p1;
p2=p1;
p1=(Pro_List)malloc(LEN1);
printf("input Program number:\n");
scanf("%d",&p1->Pro_num);
printf("input info of men player:\n");
sex=1;
p1->MenHead=creat_playerlist(p1->Pro_num,sex); /***建立这个项目的运动员链表*****/
p1->MenHead=order_playerlist(p1->MenHead,p1->Pro_num);
printf("input info of women player:\n");
sex=2;
p1->WomenHead=creat_playerlist(p1->Pro_num,sex);
p1->WomenHead=order_playerlist(p1->WomenHead,p1->Pro_num);
}
p2->next=NULL;
/****陆续建立新的项目结点,插入单链表,直到建立系数为零的结点为止********/
板凳
青竹轩主 [专家分:0] 发布于 2006-05-30 13:39:00
接上面
return(head);
}
/****************************************************/
void print_program(Pro_List head,int program_num,int sex)
{
/******according to program_num and sex*****/
Pro_List p=head;
Pla_List q=NULL;
printf("program number is %d\n",program_num);
p=head->next;
while(p->Pro_num!=program_num)
{
p=p->next;
}
if(sex==1)
{
q=p->MenHead->next;
printf("Pla_num\tSch_num\tmark\tpoint\n");
for(;q!=NULL;q=q->next)
{
printf("%d\t%d\t%d\t%d\n",q->Pla_num,q->Pla_school,q->Pla_mark,q->Pla_point);
}
}
if(sex==2)
{
q=p->WomenHead->next;
printf("Pla_num\tSch_num\tmark\tpoint\n");
for(;q!=NULL;q=q->next)
{
printf("%d\t%d\t%d\t%d\n",q->Pla_num,q->Pla_school,q->Pla_mark,q->Pla_point);
}
}
}
/********************************************************/
Sch_List creat_schoollist(void)
{
Sch_List head,p1,p2;
head=p1=p2=(Sch_List)malloc(sizeof(struct School));
head->next=NULL;
/*******建立头结点*****/
printf("\nstart to creat school_list:\n");
p1=(Sch_List)malloc(sizeof(struct School));
printf("input school num:\n");
scanf("%d",&p1->sch_num);
/********建立第一个数据结点********/
while(p1->sch_num!=0)
{
p2->next=p1;
p2=p1;
p1=(Sch_List)malloc(sizeof(struct School));
printf("input school num:\n");
scanf("%d",&p1->sch_num);
}
p2->next=NULL;
/****陆续建立新的数据结点,插入单链表,直到建立系数为零的结点为止********/
return(head);
}
/******************************************/
void print_school(Pro_List head,int school_num,Sch_List s)
{
/************according to school_num*************/
Pro_List p=head->next;
Pla_List q=NULL;
Sch_List r=s->next;
while(r->sch_num!=school_num)
{
r=r->next;
}
r->sch_men_total=0;
r->sch_women_total=0;
printf("Pla_num\tPla_sex\tprogram\tmark\tpoint\n");
for(;p!=NULL;p=p->next)
{
for(q=p->MenHead->next;q!=NULL;q=q->next)
{
if(q->Pla_school==school_num)
{
printf("%d\t%d\t%d\t%d\t%d\n",q->Pla_num,q->Pla_sex,q->Pla_program,q->Pla_mark,q->Pla_point);
if(q->Pla_point>0)
{
r->sch_men_total+=q->Pla_point;
}
}
}
for(q=p->WomenHead->next;q!=NULL;q=q->next)
{
if(q->Pla_school==school_num)
{
printf("%d\t%d\t%d\t%d\t%d\n",q->Pla_num,q->Pla_sex,q->Pla_program,q->Pla_mark,q->Pla_point);
if(q->Pla_point>0)
{
r->sch_women_total+=q->Pla_point;
}
}
}
}
}
/*********************************************/
void order_schoollist(Sch_List head)
{
Sch_List p1,p2,p;
School temp;
p1=head->next;
for(;p1->next!=NULL;p1=p1->next)
{
for(p2=p1->next;p2!=NULL;p2=p2->next)
{
if((p2->sch_men_total+p2->sch_women_total)>(p1->sch_men_total+p1->sch_women_total))
{
temp.sch_num=p1->sch_num;
p1->sch_num=p2->sch_num;
p2->sch_num=temp.sch_num;
temp.sch_men_total=p1->sch_men_total;
p1->sch_men_total=p2->sch_men_total;
p2->sch_men_total=temp.sch_men_total;
temp.sch_women_total=p1->sch_women_total;
p1->sch_women_total=p2->sch_women_total;
p2->sch_women_total=temp.sch_women_total;
}
}
}
printf("sch_num\tMtotal\tFtotal\ttotal\n");
for(p=head->next;p!=NULL;p=p->next)
{
printf("%d\t%d\t%d\t%d\n",p->sch_num,p->sch_men_total,p->sch_women_total,p->sch_men_total+p->sch_women_total);
}
printf("\n");
}
/******************************************/
main()
{
int cmd;
Pro_List head;
Sch_List s,p;
int program_num,sex,school_num,i;
printf("*****************************\n");
printf("press P to print info according to program and sex\n");
printf("press S to print info according to school\n");
printf("*****************************\n");
printf("\nSelect please:\n");
scanf("%c",&cmd);
switch(cmd)
{
case 'P':
head=creat_programlist();
printf("\n\n");
printf("input program_num:\n");
scanf("%d",&program_num);
printf("input sex:\n");
scanf("%d",&sex);
print_program(head,program_num,sex);
break;
case 'S':
head=creat_programlist();
s=creat_schoollist();
printf("input school num:\n");/**********共有几所学校参加**********/
scanf("%d",&school_num);
for(i=1;i<=school_num;i++)
{
print_school(head,i,s);
}
order_schoollist(s);
break;
default:
printf("input error!no such function!\n");
}
}
小妹妹拿去运行吧!!!
我来回复