1075 PAT Judge (25 分)(排序)

1075 PAT Judge (25 分)

The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.

Input Specification:

Each input file contains one test case. For each case, the first line contains 3 positive integers, N (≤10?4?? ), the total number of users, K (≤5), the total number of problems, and M (≤10?5?? ), the total number of submissions. It is then assumed that the user id's are 5-digit numbers from 00001 to N, and the problem id's are from 1 to K. The next line contains K positive integers p[i] (i=1, ..., K), where p[i] corresponds to the full mark of the i-th problem. Then M lines follow, each gives the information of a submission in the following format:

user_id problem_id partial_score_obtained

where partial_score_obtained is either ?1 if the submission cannot even pass the compiler, or is an integer in the range [0, p[problem_id]]. All the numbers in a line are separated by a space.

Output Specification:

For each test case, you are supposed to output the ranklist in the following format:

rank user_id total_score s[1] ... s[K]

where rank is calculated according to the total_score, and all the users with the same total_score obtain the same rank; and s[i] is the partial score obtained for the i-th problem. If a user has never submitted a solution for a problem, then "-" must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted.

The ranklist must be printed in non-decreasing order of the ranks. For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems. And if there is still a tie, then they must be printed in increasing order of their id's. For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist. It is guaranteed that at least one user can be shown on the ranklist.

Sample Input:
7 4 20
20 25 25 30
00002 2 12
00007 4 17
00005 1 19
00007 2 25
00005 1 20
00002 2 2
00005 1 15
00001 1 18
00004 3 25
00002 2 25
00005 3 22
00006 4 -1
00001 2 18
00002 1 20
00004 1 15
00002 4 18
00001 3 4
00001 4 2
00005 2 -1
00004 2 0
Sample Output:
1 00002 63 20 25 - 18
2 00005 42 20 0 22 -
2 00007 42 - 25 - 17
2 00001 42 18 18 4 2
5 00004 40 15 0 25 -
分析

當(dāng)?shù)梅质?1時(shí)戴而,表示編譯未通過,在結(jié)果集中編譯未通過的輸出0泄鹏,未提交的輸出 -,當(dāng)參賽者沒有提交題目時(shí),結(jié)果集中不輸出此用戶。

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int problem[6];
vector<vector<int> > info;
vector<bool> isshown;
struct ansnode{
    int id,sovleCnt,totalscore,rank;
};
bool cmp(ansnode a,ansnode b){
    return a.totalscore!=b.totalscore?a.totalscore>b.totalscore:(a.sovleCnt!=b.sovleCnt?a.sovleCnt>b.sovleCnt:(a.id<b.id));
}
int main(){
    int n,k,m;
    cin>>n>>k>>m;
    info.resize(n+1);
    isshown.resize(n+1);
    fill(info.begin(),info.end(),vector<int>(k+1,-1));
    for(int i=1;i<=k;i++) cin>>problem[i];
    for(int i=0;i<m;i++){
        int id,proid,sco;
        cin>>id>>proid>>sco;
        if(info[id][proid]<sco) info[id][proid]=sco;
        if(sco!=-1) isshown[id]=true;
        else if(info[id][proid]==-1){
            info[id][proid]=-2;
        }
    }
    vector<ansnode> ans;
    for (int r=1;r<=n;r++){
        int sovleCnt=0,totalscore=0;
        for(int i=1;i<=k;i++){
            if(problem[i]==info[r][i]) sovleCnt++;
            if(info[r][i]>0 ) totalscore += info[r][i];
        }
        if(isshown[r])  ans.push_back(ansnode{r,sovleCnt,totalscore,0});
    }
    sort(ans.begin(),ans.end(),cmp);
    ans[0].rank=1;
    for(int i=1;i<(int)ans.size();i++){
        if(ans[i].totalscore==ans[i-1].totalscore) ans[i].rank=ans[i-1].rank;
        else ans[i].rank=i+1;
    }
    for(int i=0;i<(int)ans.size();i++){
        int tmpid=ans[i].id;
        printf("%d %05d %d",ans[i].rank,ans[i].id,ans[i].totalscore);
        for(int j=1;j<=k;j++){
            if(info[tmpid][j]==-1) printf(" -");
            else if(info[tmpid][j]==-2) printf(" 0");
            else{
                printf(" %d",info[tmpid][j]);
            }
        }
        printf("\n");
    }
    return 0;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子界轩,更是在濱河造成了極大的恐慌热鞍,老刑警劉巖薇宠,帶你破解...
    沈念sama閱讀 219,490評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件慢睡,死亡現(xiàn)場(chǎng)離奇詭異漂辐,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)棕硫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門髓涯,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人哈扮,你說我怎么就攤上這事纬纪。” “怎么了滑肉?”我有些...
    開封第一講書人閱讀 165,830評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵包各,是天一觀的道長。 經(jīng)常有香客問我靶庙,道長问畅,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,957評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮护姆,結(jié)果婚禮上矾端,老公的妹妹穿的比我還像新娘。我一直安慰自己卵皂,他們只是感情好秩铆,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評(píng)論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著灯变,像睡著了一般殴玛。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上添祸,一...
    開封第一講書人閱讀 51,754評(píng)論 1 307
  • 那天族阅,我揣著相機(jī)與錄音,去河邊找鬼膝捞。 笑死坦刀,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的蔬咬。 我是一名探鬼主播鲤遥,決...
    沈念sama閱讀 40,464評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼林艘!你這毒婦竟也來了盖奈?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤狐援,失蹤者是張志新(化名)和其女友劉穎钢坦,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體啥酱,經(jīng)...
    沈念sama閱讀 45,847評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡爹凹,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了镶殷。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片禾酱。...
    茶點(diǎn)故事閱讀 40,137評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖绘趋,靈堂內(nèi)的尸體忽然破棺而出颤陶,到底是詐尸還是另有隱情,我是刑警寧澤陷遮,帶...
    沈念sama閱讀 35,819評(píng)論 5 346
  • 正文 年R本政府宣布滓走,位于F島的核電站,受9級(jí)特大地震影響帽馋,放射性物質(zhì)發(fā)生泄漏搅方。R本人自食惡果不足惜疫粥,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望腰懂。 院中可真熱鬧梗逮,春花似錦、人聲如沸绣溜。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽怖喻。三九已至底哗,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間锚沸,已是汗流浹背跋选。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評(píng)論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留哗蜈,地道東北人前标。 一個(gè)月前我還...
    沈念sama閱讀 48,409評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像距潘,于是被迫代替她去往敵國和親炼列。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,336評(píng)論 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    網(wǎng)事_79a3閱讀 12,081評(píng)論 3 20
  • iOS 中監(jiān)聽某個(gè)值的改變有哪些方法音比? 在一個(gè)復(fù)雜的俭尖,有狀態(tài)的系統(tǒng)中,當(dāng)一個(gè)對(duì)象的狀態(tài)發(fā)生改變洞翩,如何通知系統(tǒng)稽犁,并對(duì)...
    action愛生活閱讀 592評(píng)論 0 0
  • wxg 等我想好了已亥,我在對(duì)你說。我會(huì)對(duì)你輕輕的說循未,和你緩緩的暢談陷猫。那時(shí)秫舌,我將組織好我的語言的妖,向所有父母對(duì)嬰兒般的愛...
    silencesky閱讀 583評(píng)論 0 1
  • 0 - don’t agree that this is a usability problem/不認(rèn)為這是一個(gè)問...
    蘿卜家長閱讀 442評(píng)論 0 0