| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 512 人关注过本帖
标题:怎么和课本上不一样!??哪位大侠把每行后都注释下嘛
只看楼主 加入收藏
麦田打望者
Rank: 2
等 级:论坛游民
帖 子:62
专家分:34
注 册:2010-5-31
结帖率:77.78%
收藏
 问题点数:0 回复次数:1 
怎么和课本上不一样!??哪位大侠把每行后都注释下嘛
#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;
搜索更多相关主题的帖子: 每行 课本 注释 每行 课本 注释 
2010-07-06 17:25
麦田打望者
Rank: 2
等 级:论坛游民
帖 子:62
专家分:34
注 册:2010-5-31
收藏
得分:0 
就这样了。。。。
2010-07-06 20:50
快速回复:怎么和课本上不一样!??哪位大侠把每行后都注释下嘛
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012809 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved