怎么和课本上不一样!??哪位大侠把每行后都注释下嘛
#define LIST_INIT_SIZE 100//线性表储存空间的初始分配量#define LISTINCREMENT 10//线性表存储空间的分配增量
#define OVERFLOW -1//返回-1时储存失败
#define OK 1
#define ERROR 0
#include <stdio.h>
#include <malloc.h>//动态分配函数头文件
#include "conio.h"//控制输入输出
typedef int Status;//自定义status为int
typedef struct
{int schoolnum,itemnum;
char name[10];
int order, score;
}ElemType; //定义结构体数组,存放每个学校的比赛名次数据
typedef struct
{ElemType *elem;//指向存放线性表中元素的基地址
int length,listsize;
}SqList;
typedef struct
{int schoolnum,malescore,femalescore,allscore,order;
}CountType; //用于统计每个学校的总分情况
int n,w=2,m=3,inputnum;
CountType *sch;
{Status InitList_Sq(SqList) &L)//建立一个空顺序表
{
L.elem= (1);//空间
L.length=0;//初始长度为0
L.listsize=LIST_INIT_SIZE;//初始空间
}
{Status Input(SqList) &L,FILE *fp)
fp=fopen("data2-1","rb") //
{int i=0; ElemType *p;
if(!fp) return ERROR;//.....
while( (2) )
{fscanf(fp,"%d,%d,%d,%s",&L.elem[i].schoolnum,
&L.elem[i].itemnum, &L.elem[i].order,L.elem[i].name);//从磁盘上输入
i++;
}
L.length=i;
printf("---------------------------\n");
p=L.elem;
printf("schoolnum itemnum name order score\n");
for (i=0; i<L.length; i++,p++) //计算每个成绩的得分
{ switch( (3) )
{case 1:
switch(L.elem[i].order)
{case 1:L.elem[i].score=7; break;
case 2:L.elem[i].score=5; break;
case 3:L.elem[i].score=3; break;
case 4:L.elem[i].score=2; break;
case 5:L.elem[i].score=1; break;
} break;
case 0:
switch(L.elem[i].order)
{case 1:L.elem[i].score=5; break;
case 2:L.elem[i].score=3; break;
case 3:L.elem[i].score=2; break;
} break;
}
printf("%9d %3d %10s %5d %3d\n",
p->schoolnum,p->itemnum,p->name,p->order,p->score);
}
return OK;
}
Status Count(SqList L)//统计每个学校的男女得分及总分
{
int i,j;
ElemType *p;
CountType t;
sch=(CountType *)malloc(n*sizeof(CountType));
if(!sch) return ERROR;
for(i=1; i<=n; i++)
{
sch[i].schoolnum=i;
sch[i].malescore=sch[i].femalescore=sch[i].allscore=0;
}
for (i=0; i<L.length; i++)
{ (4);
if( (5) )
{
sch[p->schoolnum].malescore+=p->score;
sch[p->schoolnum].allscore+=p->score;
}
else if( (6) )
{
sch[p->schoolnum].femalescore+=p->score;
sch[p->schoolnum].allscore+=p->score;
}
else return ERROR;
p++;
}
for (i=1; i<n; i++) //按总分排序
for (j=1; j<=n-i; j++)
if (sch[j].allscore<sch[j+1].allscore)
{ (7) ; }
return OK;
}
void Output(SqList L) //按排名顺序输出得分情况
{
ElemType *p;
int i,j;
for (i=1; i<=n; i++)
{
p=L.elem;
printf("school item name order score\n");
while (p<L.elem+L.length)
{ if( (8) )
printf("%4d %4d %10s %5d %5d\n",p->schoolnum,
p->itemnum, p->name,p->order,p->score);
p++;
}
sch[i].order=1;
for (j=1; j<=n; j++)
if (sch[j].allscore>sch[i].allscore) sch[i].order++;
printf("\n\t\t\t allscore malescore femalescore order\n");// /t水平制表
printf("\t\t\t%9d %10d %12d %5d\n\n",sch[i].allscore,
sch[i].malescore,sch[i].femalescore, sch[i].order);
getche();//是获取键盘输入字符的ASCII码....
}
}
main()
{
SqList L;
FILE *fp;
fp=fopen("data2-1.txt","r");
if(!fp) return ERROR;
fscanf(fp,"%d",&n);
if(InitList_Sq(L))
if(Input(L,fp))
if(Count(L))
{Output(L);
return OK;
}
return ERROR;