九度OJ 題目1014:排名
阿新 • • 發佈:2019-01-06
- 題目描述:
- 今天的上機考試雖然有實時的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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 #include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> using namespace std; struct node { char name[100];//考號 int num;//做題的數目, int score;//總分數 } student[1000]; bool cmp(node a,node b) { if(a.score!=b.score) return a.score>b.score; else return strcmp(a.name,b.name)<0; } int main() { int i,j,k; int N,M,G;//N是人數,M是題目數,G; int a[10];//儲存每道題的分數; while(scanf("%d",&N)!=EOF) { int b; int numberstudent=0;//過線的人數; if(N==0) break; scanf("%d%d",&M,&G); memset(a,0,M); for(i=1; i<=M; i++) scanf("%d",&a[i]); for(j=0; j<N; j++) { student[j].score=0; scanf("%s%d",student[j].name,&student[j].num); for(int k=1; k<=student[j].num; k++) { scanf("%d",&b); student[j].score+=a[b]; } if(student[j].score>=G) numberstudent++; } sort(student,student+N,cmp); printf("%d\n", numberstudent); for(k=0; k<numberstudent; k++) { printf("%s %d\n",student[k].name,student[k].score); } } return 0; } /************************************************************** Problem: 1014 User: roye Language: C++ Result: Accepted Time:100 ms Memory:1636 kb ****************************************************************/