HDU1236: Ranking

Source: Internet
Author: User

Problem Description today's computer test has a real-time Ranklist, but the above ranking is only based on the number of completed questions, without considering the score of each question, so it is not the final ranking. Given the admission score line, please write a program to find the candidates who finally pass the score line and print their scores in descending order. The Input test Input contains information about several tests. The second row of each exam information shows the number of candidates N (0 <N <1st), number of questions M (0 <M <= 10), score line (positive integer) G; in the sorting of rows of 2nd, the positive integer score from question 1st to question M is given. In the N rows below, each row provides the admission ticket number of a candidate (a string of no more than 20 characters), the total number of questions solved by the student m, and the question number of the m question (question number from 1 to M ). When the number of students read is 0, the input is complete and the test will not be processed. For each test, Output n is the number of examinees whose scores are not lower than the scores in the 1st row, and then Output the number and score of the online examinees according to the scores in the n row, separated by 1 space. If the scores of multiple candidates are the same, the scores are displayed in ascending order of their test numbers. Sample Input4 5 2510 10 12 13 15CS004 3 5 1 3CS003 5 2 4 1 3 5CS002 2 1 2CS001 3 2 3 3 51 2 4010 30CS001 1 22 3 2010 10 10cs0000000001 0cs00000000000002 2 1 20 Sample Output3CS003 60CS001 37CS004 3701cs00000000000002 20 Hint Huge input, scanf is recommended. [cpp] # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace std; # define N 1005 int que [15]; struct node {char name [25]; int num; int sum;} stu [N]; bool cmp (const node & a, const node & B) {if (. sum = B. sum) return strcmp (. name, B. name) <0? 1: 0; else return. sum> B. sum;} int main () {int stu_num, text_num, line, a, cnt; while (scanf ("% d", & stu_num )! = EOF & stu_num) {cnt = 0; int I; scanf ("% d", & text_num, & line); for (I = 1; I <= text_num; I ++) scanf ("% d", & que [I]); for (I = 1; I <= stu_num; I ++) {stu [I]. sum = 0; scanf ("% s % d", stu [I]. name, & stu [I]. num); while (stu [I]. num --) {scanf ("% d", & a); stu [I]. sum + = que [a];} if (stu [I]. sum> = line) cnt ++;} sort (stu + 1, stu + 1 + stu_num, cmp); cout <cnt <endl; for (I = 1; I <= stu_num; I ++) {if (stu [I]. sum> = line) printf ("% s % d \ n", stu [I]. name, stu [I]. sum); else break;} return 0 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.