您的位置:首页 > 其它

4000 PAT 甲级2017_12_09_B_Final_Grading_25_2

2018-01-16 17:42 330 查看
B. Final Grading (25)

时间限制

100 ms

内存限制

65536 kB

代码长度限制

8000 B

判题程序

Standard

作者

CHEN, Yue

For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final
grade no less than 60 out of 100. The final grade is calculated by G = (Gmid-termx 40% + Gfinalx 60%) if Gmid-term > Gfinal, or Gfinal will be taken as the final grade G. Here Gmid-term and Gfinal are the student's scores of the mid-term and the final exams,
respectively.

The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.

Input Specification:

Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on
the final exam list. All the numbers are no more than 10,000.

Then three blocks follow. The first block contains P online programming scores Gp's; the second one contains M mid-term scores Gmid-term's; and the last one contains N final exam scores Gfinal's. Each score occupies a line with the format: StudentID Score,
where StudentID is a string of no more than 20 English letters and digits, and Score is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).

Output Specification:

For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format:

StudentID Gp Gmid-term Gfinal G

If some score does not exist, output "-1" instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID's. It is guaranteed that the StudentID's
are all distinct, and there is at least one qualified student.

Sample Input:

6 6 7

01234 880

a1903 199

ydjh2 200

wehu8 300

dx86w 220

missing 400

ydhfu77 99

wehu8 55

ydjh2 98

dx86w 88

a1903 86

01234 39

ydhfu77 88

a1903 66

01234 58

wehu8 84

ydjh2 82

missing 99

dx86w 81

Sample Output:

missing 400 -1 99 99

ydjh2 200 98 82 88

dx86w 220 88 81 84
wehu8 300 55 84 84   

#include<stdio.h>
#include<string.h>
struct student{
char id[20];
int pro;
int mid;
int fin;
int g;
};
void cpy(char a[],char b[],int n,int N)
{
int i;
for(i=0;i<n;i++)
{
a[i]=b[i];
}
for(i=n;i<N;i++)
{
a[i]='\0';
}
}
int main()
{
int p,m,n;
scanf("%d %d %d",&p,&m,&n);
int i,j,x,nst; //i,j循环变量,x,a[20]暂存输入数据,nst 可能满足要求录入个数
char a[20];
struct student st[10000];
nst=0;
for(i=0;i<p;i++)
{
scanf("%s %d",a,&x); //输入program
if(x>=200) //可能满足要求的学生个数
{
strcat(st[nst].id,a);
st[nst].pro=x,st[nst].mid=-1,st[nst].fin=-1,st[nst].g=-1;
nst++;
}
}
//for(i=0;i<p;i++) printf("%s %d",st[i].id,st[i].pro);
//p=nst;
for(i=0;i<m;i++) //输入mid
{
scanf("%s %d",a,&x);
for(j=0;j<p;j++) //是否为已录入同学
{
if(strcmp(a,st[j].id)==0) //是已录入同学
{
st[j].mid=x; //修改mid成绩
break;
}
}
//若是新同学则不满足获得证书要求,因为没有Pro成绩
// if(j==st) //新student ID
// {
// strcat(st[nst].id,a); //录入新同学
// nst++;
// }
}
for(i=0;i<n;i++) //录入fin
{
scanf("%s %d",a,&x);
if(x>=60) //可能满足要求
{
for(j=0;j<nst;j++)
{
if(strcmp(a,st[j].id)==0) //录入同学
{
if(x<st[j].mid) //fin<mid
{
int gg;
st[j].fin=x;
gg=st[j].mid*0.4+x*0.6;
st[j].g=(int)(gg+0.5);
}
else //fin>mid
{
st[j].fin=x;
st[j].g=x;
}
break;
}
}
}
}
for(i=0;i<nst;i++) //g排序
{
if(st[i].g>0)
{
for(j=i+1;j<nst;j++)
{
if(st[i].g<st[j].g||st[j].g==st[i].g&&strcmp(st[i].id,st[j].id)>0) //ig<jg或iid>jid
{
int xx;
char yy[20];
xx=st[i].g,st[i].g=st[j].g,st[j].g=xx;
xx=st[i].mid,st[i].mid=st[j].mid,st[j].mid=xx;
xx=st[i].fin,st[i].fin=st[j].fin,st[j].fin=xx;
xx=st[i].pro,st[i].pro=st[j].pro,st[j].pro=xx;
strcat(yy,st[i].id),cpy(st[i].id,st[j].id,strlen(st[j].id),20),cpy(st[j].id,yy,strlen(yy),20);
}
}
printf("%s %d %d %d %d\n",st[i].id,st[i].pro,st[i].mid,st[i].fin,st[i].g);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: