一、题目
二、源代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Student
{
char no[21];
int gp,gm,gf,g,flag;
};
int cmp1(const void* a,const void* b)
{
struct Student *c=(struct Student *)a;
struct Student *d=(struct Student *)b;
return strcmp(c->no,d->no);
}
int cmp2(const void* a,const void* b)
{
struct Student *c=(struct Student *)a;
struct Student *d=(struct Student *)b;
if(c->flag!=d->flag) return d->flag - c->flag;
return d->g - c->g;
}
int main()
{
int p,m,n,i,score,count=0;
char no[21];
struct Student s[10000],*j;
scanf("%d %d %d",&p,&m,&n);
for(i=0;i<p;i++)
{
scanf("%s %d",no,&score);
if(score>=200)
{
strcpy(s[count].no,no);
s[count].gp=score;
s[count].gm=-1;
s[count].gf=-1;
s[count].g=0;
s[count].flag=0;
count++;
}
}
qsort(s,count,sizeof(struct Student),cmp1);
for(i=0;i<m;i++)
{
scanf("%s %d",no,&score);
j = (struct Student*)bsearch(no,s,count,sizeof(struct Student),cmp1);
if(j!=NULL)j->gm=score;
}
for(i=0;i<n;i++)
{
scanf("%s %d",no,&score);
j = (struct Student*)bsearch(no,s,count,sizeof(struct Student),cmp1);
if(j!=NULL)
{
j->gf=score;
if(j->gm>j->gf)
{
j->g=(int)((double)j->gm*0.4+(double)j->gf*0.6+0.5);
if(j->g>=60) j->flag=1;
}
else
{
j->g=j->gf;
if(j->g>=60)j->flag=1;
}
}
}
qsort(s,count,sizeof(struct Student),cmp2);
for(i=0;i<count;i++)
{
if(s[i].flag==0)break;
printf("%s %d %d %d %d\n",s[i].no,s[i].gp,s[i].gm,s[i].gf,s[i].g);
}
return 0;
}
三、运行结果