题目1014:排名

来源:互联网 发布:三国志9优化伴侣设置 编辑:程序博客网 时间:2024/05/21 11:05
题目1014:排名

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:9965

解决:3027

题目描述:
    今天的上机考试虽然有实时的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 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
样例输出:
3CS003 60CS001 37CS004 3701CS000000000000000002 20
//////  有bug。。一直AC不了,求大佬指教///#include <stdio.h>#include <iostream>#include <stack>#include <string.h>#include <queue>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <set>#include <string>using namespace std;typedef long long LL;bool cmp(pair<string, int> a, pair<string, int> b){    if(a.second != b.second){        return a.second > b.second;    }else {        return a.first < b.first;    }}int main() {    freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);    int N, M, GradeLine;    while(scanf("%d",&N) != EOF) {        if(N == 0){            break;        }        scanf("%d %d",&M, &GradeLine);        vector<int> Grade;        map<string, int> mapp;        for(int i = 0; i < M; i++){            int temp;            cin >> temp;            Grade.push_back(temp);        }        int K = 0;        for(int i = 0; i < N; i++){            string str;            int temp, ans = 0;            cin >> str >> temp;            for(int i = 0; i < temp; i++){                int T;                cin >> T;                ans += Grade[T - 1];            }            if(ans >= GradeLine){                mapp[str] = ans;                K++;            }        }        cout << mapp.size() << endl;        vector<pair<string, int> > v(mapp.begin(), mapp.end());        sort(v.begin(), v.end(), cmp);        vector<pair<string, int> >::iterator iter;        for(iter = v.begin(); iter != v.end(); iter++){            cout << iter -> first << " " << iter -> second << endl;        }    }    return 0;}

原创粉丝点击