HDU2093 Exam Ranking "water problem"

Source: Internet
Author: User

Exam Rankings

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total Submission (s): 9760 Accepted Submission (s): 3401
Problem Description
The C + + programming exam uses a real-time submission system that features instant performance rankings. How is its function implemented?
We have done the answer to the question, after the submission, either "AC", or wrong, regardless of the wrong method, always put a note to you, indicating that you have a mistake to submit, so once you submit the topic "AC", you will be counted, the total number of errors submitted several back. Although you are striding up a step in the number of questions, you have to spend time on it. In particular, there have been errors submitted, each time must be amortized on a certain unit time points. In this way, you may be a lot more likely to lead others in the number of questions you make, but you may be at a disadvantage in the time-consuming rankings of people who do the same number of questions.
For example: A total of 8 questions (A,B,C,D,E,F,G,H), each of the questions are in the corresponding title number under the number of marks, negative numbers indicate that the student has been wrong to submit the number of times, but until now there is no AC, positive indicates the time spent on AC, if positive A followed by a pair of parentheses, There is an integer b, that means the student submits the topic AC, consumes time a, and at the same time, has been wrongly submitted B, so for the following input data:
If the penalty for each error is divided into 20 points, then its ranking from high to low should be this:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0

Input
The first line of input data is the number of test questions N (1≤n≤12) and the unit penalty score m (10≤m≤20), each row of data describes a student's user name (no more than 10 characters of string) and the status of all n questions, which describes the format of the quantity tag in the problem description, see the table above, The commit times are always less than 100,ac time is always less than 1000.

Output
The status of these students ' exams will be output in a real-time ranking. Real-time rankings are obviously first by the number of AC questions, many in front, and then by the time of the number of rows, less in front, if the coincidence before the two are equal, then by the name of the dictionary sequence, small in front. Each student occupies a row, the output name (10 characters justifies), the number of questions (2 characters justifies, right alignment) and time (4 characters justifies, right-aligned). There is a space between the name, the number of questions, and the time division.

Sample Input
8 20
Smith -1 -16 8 00120 39 0
John 116 -2 11 0082 55 (1)0
Josephus 72 (3) 12610-3 0 47 21 (2)-2
Bush 0 -1 -8 000 0 0
Alice -2 67 (2) 13 -1 0 13379 (1)-1
Bob 0 0 57 (5) 0 0 168-70

Sample Output
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0

Author
Qianneng

Source

Welcome to the new semester-super easy version


Title: OJ Real-time ranking system sorting

Idea: Use the structure to save each person's name, do the number of questions and the total time spent. And then calculate the number of each person's problem.

And the total time spent, then ranked. The SSCANF function is used in the code. You can extract the number of characters in a string by "%d"

format to int d. Find () in string, the return value of the function is: Returns the element if it is found

The position in the string, otherwise returns a specific value of string::npos (that is,-1).


#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <    Cstring>using namespace Std;struct node{string Name;    int Num; int time;}    A[1100];int CMP (Node A,node b) {if (a.num! = b.num) return a.num > B.num;        else {if (a.time! = b.time) return A.time < B.time;        else {return A.name < b.name;    }}}int Main () {int n,m,count = 0;    String name,temp;    CIN >> N >> M; while (CIN >> name) {A[count].        name = name; A[count].        Num = 0; A[count].        Time = 0;            for (int i = 0; i < N; ++i) {cin >> temp;            if (temp[0]== '-' | | temp[0] = = ' 0 ') continue;            int D;            SSCANF (Temp.c_str (), "%d", &d); A[count].            num++; A[count].            time+= D;            int pos = Temp.find (' ('); if (pos! = String::npos) {sscanf (Temp.c_str () +pos+1, "%d", &d); A[count].            Time + = (d*m);    }} count++;    } sort (a,a+count,cmp); for (int i = 0; I <= Count-1; i++) {printf ("%-10s%2d%4d\n", A[i]. Name.c_str (), A[i]. Num, A[i].    Time); } return 0;}


HDU2093 Exam Ranking "water problem"

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.