⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog1.bak

📁 计算机等级考试 四级 机试总汇 历年真题
💻 BAK
字号:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <mem.h>
#include <stdlib.h>
#define MAX 50

typedef struct {
  char xh[5];
  char xm[7];
  int  sx,yw,wy,wl,hx,zz,zf;
} STUD;

STUD stud[50] ;

void ReadDat(STUD stud[50])
{
  FILE *fp ;
  char str[30], tmp[4] ;
  int i ;

  fp = fopen("stud.dat","rb") ;
  clrscr() ;
  tmp[3] = 0 ;
  for(i = 0 ; i < MAX ; i++) {
  fread(&stud[i],sizeof(STUD),1,fp);
  stud[i].zf = stud[i].sx+stud[i].yw+stud[i].wy+stud[i].wl+stud[i].hx+stud[i].zz ;
  }
  fclose(fp) ;
}

void sort(STUD stud[50])
{
int flag=1,i=0,temp=0,j=1;
STUD tt;
   while (i<MAX) {
    while (j<MAX) {
     if (stud[j].zf>stud[temp].zf)
	{temp=j;}
     else
	{if (stud[j].zf==stud[temp].zf)
	  if (strcmp(stud[j].xh,stud[temp].xh)>0)
	    {temp=j;}
	  }
     j++;

    }/* while(j<MAX) end */
    strcpy(tt.xh,stud[i].xh);strcpy(tt.xm,stud[i].xm);
    tt.sx=stud[i].sx;tt.yw=stud[i].yw;
    tt.wy=stud[i].wy;tt.wl=stud[i].wl;
    tt.hx=stud[i].hx;tt.zz=stud[i].zz;
    tt.zf=stud[i].zf;
    strcpy(stud[i].xh,stud[temp].xh);strcpy(stud[i].xm,stud[temp].xm);
    stud[i].sx=stud[temp].sx;stud[i].yw=stud[temp].yw;
    stud[i].wy=stud[temp].wy;stud[i].wl=stud[temp].wl;
    stud[i].hx=stud[temp].hx;stud[i].zz=stud[temp].zz;
    stud[i].zf=stud[temp].zf;
    strcpy(stud[temp].xh,tt.xh);strcpy(stud[temp].xm,tt.xm);
    stud[temp].sx=tt.sx;stud[temp].yw=tt.yw;
    stud[temp].wy=tt.wy;stud[temp].wl=tt.wl;
    stud[temp].hx=tt.hx;stud[temp].zz=tt.zz;
    stud[temp].zf=tt.zf;
    i++;
    temp=i;j=temp+1;

   } /* while (i<MAX) end */


}

writedat()
{ FILE *fp;
 int i;
  fp = fopen("stud.dat","wb") ;
  for(i = 0 ; i < MAX ; i++) {
    if (i<10) sprintf(stud[i].xh,"%s%d","0",i+1);
     else     sprintf(stud[i].xh,"%d",i+1);
    sprintf(stud[i].xm,"%s%d","aa",i+1);
    stud[i].sx=random(100);
    stud[i].yw=random(100);
    stud[i].wy=random(100);
    stud[i].wl=random(100);
    stud[i].hx=random(100);
    stud[i].zz=random(100);
    fwrite(&stud[i],sizeof(STUD),1,fp);
    printf("%4s%6s%3d%3d%3d%3d%3d%3d\n",stud[i].xh,stud[i].xm,stud[i].sx,stud[i].yw,stud[i].wy,stud[i].wl,stud[i].hx,stud[i].zz) ;
  }
  fclose(fp) ;


}

void main()
{
  STUD stud[50] ;
  int i ;
  FILE *fp ;
  ReadDat(stud) ;
  sort(stud) ;
  fp = fopen("stud1.dat","w") ;
  for(i = 0 ; i < MAX ; i++) {
    fprintf(fp,"%4s%6s%3d\n",stud[i].xh,stud[i].xm,stud[i].zf) ;
    printf("%2d %4s %6s %3d\n",i+1,stud[i].xh,stud[i].xm,stud[i].zf) ;
    if((i % 20 == 0) && i != 0) getch() ;
  }
  fclose(fp) ;
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -