天天看點

2005年浙大研究所學生複試上機真題-排名

/*題目描述: 
    今天的上機考試雖然有實時的Ranklist,但上面的排名隻是根據完成的題數排序,沒有考慮每題的分值,是以并不是最後的排名。
	給定錄取分數線,請你寫程式找出最後通過分數線的考生,并将他們的成績按降序列印。
輸入: 
    測試輸入包含若幹場考試的資訊。每場考試資訊的第1行給出考生人數N ( 0 < N < 1000 )、考題數M ( 0 < M < = 10 )、
	分數線(正整數)G;第2行排序給出第1題至第M題的正整數分值;以下N行,
	每行給出一名考生的準考證号(長度不超過20的字元串)、該生解決的題目總數m、以及這m道題的題号(題目号由1到M)。 
    當讀入的考生人數為0時,輸入結束,該場考試不予處理。

輸出: 
    對每場考試,首先在第1行輸出不低于分數線的考生人數n,随後n行按分數從高到低輸出上線考生的考号與分數,
	其間用1空格分隔。若有多名考生分數相同,則按他們考号的升序輸出。

樣例輸入: 
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
1 2 40
10 30
CS001 1 2
2 3 20
10 10 10
CS000000000000000001 0
CS000000000000000002 2 1 2
0
樣例輸出: 
3
CS003 60
CS001 37
CS004 37
0
1
CS000000000000000002 20
*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
typedef struct{
	char id[25];
	int grade;
}student;

student t[1002];
bool cmp(student a,student b)
{
	if(a.grade!=b.grade)
		return a.grade>b.grade;
	else
		return strcmp(a.id,b.id)<0;
}
int main()
{
	int N,M,G,num;
	int pro[12];
	int a,total,i;
//	freopen("f:/in.txt","r",stdin);
	while(~scanf("%d",&N) && N)
	{
		scanf("%d%d",&M,&G);
		num=0;
		for(i=0;i<N;i++)
			t[i].grade=0;//初始化

		for(int s=1;s<=M;s++)
			scanf("%d",&pro[s]);

		for(i=0;i<N;i++)
		{
			cin>>t[i].id>>total;
			for(int j=1;j<=total;j++)
			{
				scanf("%d",&a);
                t[i].grade+=pro[a];
			}
			if(t[i].grade>=G)
				num++;
		}
		printf("%d\n",num);
		sort(t,t+N,cmp);
		for(i=0;i<num;i++)
			cout<<t[i].id<<" "<<t[i].grade<<endl;
	}
//	fclose(stdin);
	return 0;
}           

繼續閱讀