http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=2923
dic字典文件有其固定的文件格式,包括文件头和文件体,读取文件头的相应的信息,存储进变量,然后转换输出就OK了!
下面是我的代码:
#include “stdio.h”
#include “stdlib.h”
#include “string.h”
struct student
{
char name[11];
char m;
int begin;
char l;
char s;
char q[14];
};
int main()
{
struct student stu1,stu2,stu3;
FILE *fp;
int n,a=0,b=0,c=0,i,j;
float z;
char f,p[20]=””,na[20];
scanf(“%d”,&n);
scanf(“%s”,na);
if(n==1)
fp=fopen(“aaa.dic”,”rb”);
if(n==2)
fp=fopen(“bbb.dic”,”rb”);
if(fp==NULL){
exit(1);
}
fread(&a,4,1,fp);
fread(&a,4,1,fp);
fread(&b,2,1,fp);
fread(&c,2,1,fp);
fread(&stu1,4,5,fp);
for(i=1;i<=(b-33)/32;i++)
{
fread(&stu1,32,1,fp);
if(strcmp(stu1.name,”name”)==0)
stu2=stu1;
if(strcmp(stu1.name,”math”)==0)
stu3=stu1;
}
fread(&stu1,1,1,fp);
for(i=1;i<=a;i++)
{
fread(&stu1,stu2.begin,1,fp);
for(j=0;j<stu2.l;j++)
{
fscanf(fp,”%c”,&p[j]);
if(p[j]==32){
p[j]=0;
}
}
if(strcmp(p,na)==0)
{
fread(&stu1,stu3.begin-stu2.begin-stu2.l,1,fp);
fscanf(fp,”%f”,&z);
printf(“%.1f\n”,z);
break;
}
else
fread(&stu1,c-stu2.begin-stu2.l,1,fp);
}
if(i==a+1)
printf(“No\n”);
fclose(fp);
return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation