hdu1236

来源:互联网 发布:知乎 豆瓣全部电影 编辑:程序博客网 时间:2024/06/05 04:45

排名

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15591    Accepted Submission(s): 5655
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1236

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 20
Hint
Huge input, scanf is recommended.
解题思路:
这题我都不想说啥了,明显的简单题,可是还是RE、WA了好几次······
教训就是长循环里一定要看清里面的循环变量,通常都愿意用 i ,外面用 i 了,里面可换 j 吧·····
题意说的太麻烦,简化下就是先输入n人,然后输入m,代表m门课的学分,然后输入及格分。
接下来n行输入,每行先输入学生学号,然后输入k,表示他写了k道题,接下来k次循环,输入写的
题号。最后如果他及格了,那么就放进结构体数组。然后排个序,输出(注意输出要求)。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int d[101];struct node{    string a;    int b;}q[1010];string ch;bool cmp(node x ,node y){    if(x.b == y.b)        return x.a < y.a;    return x.b > y.b;}int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n;    while(~scanf("%d",&n) && n)    {        int M, G;        scanf("%d%d",&M,&G);        memset(d , 0 ,sizeof(d));        for(int i = 1 ;i <= M ; i ++)            scanf("%d",&d[i]);        int k;        int num , sum;        int t = 0;        for(int i = 0 ; i < n ; i ++)        {            cin >> ch;            scanf("%d",&k);            sum = 0;            for(int j = 0 ; j < k ; j ++)            {                scanf("%d",&num);                sum += d[num];            }            if(sum >= G)            {                q[t].a = ch;                q[t++].b = sum;            }        }        sort(q , q + t , cmp);        printf("%d\n",t);        for(int i = 0 ; i < t ; i ++)        {            cout << q[i].a << " ";            printf("%d\n", q[i].b);        }    }}


0 0
原创粉丝点击