1025. PAT Ranking (25)

Source: Internet
Author: User

Description: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. now it is your job to write a program to correctly merge all the ranklists and generate the final rank. input Specification: Each input file contains one te St case. for each case, the first line contains a positive number N (<= 100), the number of test locations. then N ranklists follow, each starts with a line containing a positive integer K (<= 300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. all the numbers in a line are separated by a space. output Specification: For each test case, first print in one line the total number of testees. then print the final ranklist in the following format: registration_number final_rank location_number local_rankThe locations are numbered from 1 to N. the output must be sorted in nondecreasing order of the final ranks. the testees with the same score must have the same rank, and the output must be sorted in nondecreasing ord Er of their registration numbers. sample Input: 251234567890001 951234567890005 1001234567890003 951234567890002 771234567890004 8541234567890013 651234567890011 251234567890014 85 Sample Output: 91234567890005 1 1 11234567890014 1 2 11234567890001 3 1 21234567890003 3 1 21234567890004 5 1 41234567890012 5 2 21234567890002 7 1 51234567890013 8 2 31234567890011 9 2 4 analysis :( 1) sort and merge the struct. (2) Pay attention to processing in the case of the same grade. Reference code:

# Include <iostream> # include <string> # include <algorithm> # include <vector> # include <functional> using namespace std; typedef struct student {string num; int grade; int final_rank; int location_num; int local_rank; // note the following code: bool operator> (const student & s) const {if (grade! = S. grade) return grade> s. grade; else return num <s. num ;}} student; # define max 30000 # define INF 0x6FFFFFFFvector <student> v; int main () {int n, m; int I, j; cin> n; for (I = 0; I <n; I ++) {cin> m; vector <student> temp (m); for (j = 0; j <m; j ++) {cin> temp [j]. num> temp [j]. grade; temp [j]. location_num = I + 1;} sort (temp. begin (), temp. end (), greater <student> (); int nowGrade = INF; int nowRank = 0; for (j = 0; j <m; j ++) {// cout <temp [j]. num <"" <temp [j]. location_num <endl; if (temp [j]. grade = nowGrade) temp [j]. local_rank = nowRank; else {temp [j]. local_rank = j + 1; nowRank = j + 1; nowGrade = temp [j]. grade;} v. push_back (temp [j]) ;}// process global_ranksort (v. begin (), v. end (), greater <student> (); // greater is used here. The header file should include # include <functional> int nowGrade = INF; int nowRank = 0; cout <v. size () <endl; for (I = 0; I <v. size (); I ++) {if (v [I]. grade = nowGrade) v [I]. final_rank = nowRank; else {nowRank = I + 1; v [I]. final_rank = I + 1; nowGrade = v [I]. grade;} cout <v [I]. num <"" <v [I]. final_rank <"" <v [I]. location_num <"<v [I]. local_rank <endl;} return 0 ;}

 


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.