HDU-1236-ranking [using library functions for simple sorting]

Source: Internet
Author: User

 

Ranking

 

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 12784 Accepted Submission (s): 4765

Problem Description

Although today's computer test has a real-time Ranklist, the above ranking is only based on the number of completed questions, not considered
The score of each question, so it is not the final ranking. Given the admission score line, please write a program to find the last score line
Candidates, and print their scores in descending order.

Input

The test input contains information about several tests. The number of candidates N (0 <N
<1000), number of questions M (0 <M <= 10), number of scores (positive integer) G; 2nd rows of sorting give a positive integer score from question 1st to question M; N rows below, each row has one
The admission ticket number of the examinee (a string of no more than 20 characters), the total number of questions that the student solves, and the question number of the m question
(The question number ranges from 1 to M ).
When the number of students read is 0, the input is complete and the test will not be processed. Output for each test, first Output the number of candidates not lower than the score line n in the 1st rows, and then the number of n rows according to the score from the high
Output The examination numbers and scores of online candidates at a low level, separated by 1 space. If multiple candidates share the same score
Number. 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. 

 

 

Code:

 

The first thought was to directly use the library sort function. Why didn't I stick to it ??!

Later, I changed the sort of count, which is very troublesome. My God, I am suffering...

Back in the order of the last address of the sort written into the number of students n, so to change to the k-1 is correct, but if there is a structure array initialization in advance, the redundant ones can be placed at the backend ~

 

# Include "stdio. h "# include" string. h "# include" iostream "# include" algorithm "using namespace std; typedef struct info {char num [22]; int mark;} info; info stu [1005]; int cmp (info a, info B) {if (. mark> B. mark) return 1; if (. mark = B. mark) {if (strcmp (. num, B. num) <0) return 1; else return 0;} return 0;} int main () {int n, m, line; // n students, m questions int I, j, k, fullmark [11], sum, index, num; char str [22]; info equal [1005], re [1005]; while (scanf ("% d", & n), n) {// for (I = 0; I <1005; I ++) // struct initialization ~ // {// Stu [I]. mark = 0; // memset (stu [I]. num, 0, sizeof (stu [I]. num); //} scanf ("% d", & m, & line); for (I = 1; I <= m; I ++) scanf ("% d", & fullmark [I]); k = 1; for (I = 1; I <= n; I ++) {scanf ("% s", str); scanf ("% d", & num); sum = 0; for (j = 1; j <= num; j ++) {scanf ("% d", & index); sum + = fullmark [index];} if (sum> = line) // only store the line ~ {Strcpy (stu [k]. num, str); stu [k ++]. mark = sum ;}} printf ("% d \ n", k-1); sort (stu + 1, stu + k, cmp); // an error occurred here .. for (I = 1; I <= K-1; I ++) printf ("% s % d \ n", stu [I]. num, stu [I]. mark);} return 0 ;} /* 6 5 2510 10 12 13 15CS004 3 5 1 3CS003 5 2 4 1 3 5CS002 2 1 2CS001 3 2 3 5CS005 3 3 5CS006 3 5 1 3 */

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.