HDU 1236 排名

來源:互聯網
上載者:User

標籤:des   style   http   color   java   os   io   strong   

/*
題目大意:求按分數的排名次序和求出分數在G以上的人數。
解題思路:見下面的注釋
痛點詳解:結構體數組的每一個元素都具有相同的結構體類型。在實際應用中,經常用結構體數組來表示具有相同資料結構的一個群體。如一個班的學生檔案,一個車間職工的工資表等。
關鍵點:二級結構體排序
解題人:lingnichong
解題時間:2014/08/06    10:35
解題感受:就是結構體的排序,還有就是看好題意
*/


排名Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15464    Accepted Submission(s): 5602

Problem Description今天的上機考試雖然有即時的Ranklist,但上面的排名只是根據完成的題數排序,沒有考慮 
每題的分值,所以並不是最後的排名。給定錄取分數線,請你寫程式找出最後通過分數線的 
考生,並將他們的成績按降序列印。 
 
Input測試輸入包含若干場考試的資訊。每場考試資訊的第1行給出考生人數N ( 0 < N 
< 1000 )、考題數M ( 0 < M < = 10 )、分數線(正整數)G;第2行排序給出第1題至第M題的正整數分值;以下N行,每行給出一 
名考生的准考證號(長度不超過20的字串)、該生解決的題目總數m、以及這m道題的題號 
(題目號由1到M)。 
當讀入的考生人數為0時,輸入結束,該場考試不予處理。 
 
Output對每場考試,首先在第1行輸出不低於分數線的考生人數n,隨後n行按分數從高 
到低輸出上線考生的考號與分數,其間用1空格分隔。若有多名考生分數相同,則按他們考 
號的升序輸出。 
 
Sample Input
4 5 2510 10 12 13 15CS004 3 5 1 3CS003 5 2 4 1 3 5CS002 2 1 2CS001 3 2 3 51 2 4010 30CS001 1 22 3 2010 10 10CS000000000000000001 0CS000000000000000002 2 1 20
 
Sample Output
3CS003 60CS001 37CS004 3701CS000000000000000002 20HintHuge input, scanf is recommended. 
 
Source浙大電腦研究生複試上機考試-2005年 
RecommendJGShining   |   We have carefully selected several similar problems for you:  1231 1228 1237 1235 1230  

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct per{char number[25];int total;}stu[1100];int cmp(per x,per y)//二級結構體排序{if(x.total != y.total)return x.total > y.total;return strcmp(x.number,y.number) < 0;}int main(){int N,M,G;int i,j,score[12];int n,sum,m;int k;while(scanf("%d", &N), N){k=0;memset(stu,0,sizeof(stu));memset(score,0,sizeof(score));scanf("%d%d", &M, &G);for(i = 1; i <= M; i++)//要根據題號來給相應的題賦予分數scanf("%d", &score[i]);getchar();//下一個是輸入字元的所以要用getchar();for(i = 0; i < N; i++){scanf("%s", stu[i].number);sum=0;scanf("%d", &n);for(j = 0; j < n; j++)//求出每個人的總得分{scanf("%d", &m);sum+=score[m];}stu[i].total=sum;}for(i = 0; i < N; i++)//算出分數大於等於G的人數{if(stu[i].total>=G)k++;}sort(stu,stu+N,cmp);//排序//for(i = 0; i < N; i++)//printf("%s %d\n",stu[i].number,stu[i].total);printf("%d\n", k);for(i = 0; i < N; i++){if(stu[i].total>=G)printf("%s %d\n",stu[i].number,stu[i].total);}}return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.