Rank list
Time limit:10000 ms |
|
Memory limit:65536 K |
Total submissions:7883 |
|
Accepted:2561 |
Description
Li Ming is a good student. he always asks the teacher about his rank in his class after every exam, which makes the teacher very tired. so the teacher gives him the scores of all the student in his class and asked him to get his rank by himself. however, he has so far classmates, and he can't know his rank easily. so he tends to you for help, can you help him?
Input
The first line of the input contains an integer N (1 <= n <= 10000), which represents the number of student in Li Ming's class. then come n lines. each line contains a name, which has no more than 30 letters. these names represent all the students in Li Ming's class and you can assume that the names are different from each other.
In (n + 2)-th line, you'll get an integer m (1 <= m <= 50 ),
Which represents the number of exams. The following M parts each
Represent an exam. Each exam has n lines. In each line, there is
Positive Integer s, which is no more then 100, and a name P, which must
Occur in the name list described above. It means that in this exam
Student P gains s scores. it's confirmed that all the names in the name
List will appear in an exam.
Output
The
Output contains M lines. In the I-th line, you should give the rank
Li Ming after the I-th exam. The rank is decided by the total scores. If
Li Ming has the same score with others, he will always in front
Others in the rank list.
Sample Input
3li mingab249 Li ming49 a48 b80 a85 B83 Li Ming
Sample output
12
Meaning understanding:
(1) Here, each ranking is the ranking that needs to be accumulated with previous scores ---- note this
(2) place it in the graph to search for scores by name. Here, the key is the name and value is the score. Add up the scores every time.
(3) note that when using gets, you must first wrap the carriage return or space on the front side with getchar.
(4) finding a ranking is a direct traversal to determine the ranking position.
# Include <iostream> # Include <Stdio. h> # Include <Stdlib. h> # Include <Map>Using Namespace STD; Int Main (){ Int N; // N students Char Name [ 35 ]; // Student name Int SCO; // Li Ming's score Int Rank;// Li Ming's ranking Int M; // M exam Int Score; // Total score table // Score list ing table Map < String , Int > Stu_sco; CIN > N; getchar (); // Be sure to eat the carriage return line break. For ( Int I = 1 ; I <= N; I ++ ){ // Read name Gets (name ); // Initialization, so that each student's score is 0 Stu_sco.insert (make_pair (name, 0 );} CIN > M; getchar (); // Be sure to eat the carriage return line break. While (M -- ) {Rank = 1 ; For ( Int I = 1 ; I <= N; I ++ ) {CIN > Score; getchar (); // Be sure to eat spaces ..... Gets (name); Map <String , Int >:: Iterator it = Stu_sco.find (name); it -> Second + = Score; If (It-> first. Compare ( " Li Ming " ) = 0 ) SCO = It-> Second ;} For (Map < String ,Int >:: Iterator it = stu_sco.begin (); it! = Stu_sco.end (); It ++ ) If (It-> second> SCO) rank ++; // Someone has a better score than him, and he needs to rank back Cout <rank < Endl ;} Return 0 ;}