1025. PAT Ranking (25)
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 test 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_rank
The 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 order of their registration numbers.
Sample Input:2 5 1234567890001 95 1234567890005 100 1234567890003 95 1234567890002 77 1234567890004 85 4 1234567890013 65 1234567890011 25 1234567890014 100 1234567890012 85Sample Output:
9 1234567890005 1 1 1 1234567890014 1 2 1 1234567890001 3 1 2 1234567890003 3 1 2 1234567890004 5 1 4 1234567890012 5 2 2 1234567890002 7 1 5 1234567890013 8 2 31234567890011 9 2 4
</pre>#include <iostream><br />#include <cstring><br />#include <algorithm><br />#define SIZE 30009<br />////////////////////////////////////////////////////////////////<br />//where is the bug?? should be taken care why conting method can not <br />//approved this time?<br />//<br />//FOUND THE BUG!!! THE RESULT OF STRCMP IS *P1-*P2 WHERE THE VALUE TO <br />//BE COMPARED ARE DIFFERENT,NOT JUST 1 OR -1, IT MAY BE -2 5 ETC.<br />/////////////////////////////////////////////////////////////////<br />using namespace std;<br /><br /><br />struct Record{<br /><span style="white-space:pre"> </span>Record();<br /><span style="white-space:pre"> </span>char ID[16];<br /><span style="white-space:pre"> </span>int score;<br /><span style="white-space:pre"> </span>int location;<br /><span style="white-space:pre"> </span>int local_rank;<br /><span style="white-space:pre"> </span>int total_rank;<br />};<br /><br /><br />Record::Record(){<br /><span style="white-space:pre"> </span>*ID='\0';<br /><span style="white-space:pre"> </span>score = 0;<br /><span style="white-space:pre"> </span>location = 0;<br /><span style="white-space:pre"> </span>local_rank =0;<br /><span style="white-space:pre"> </span>total_rank =0;<br />}<br /><br /><br />Record records[SIZE];<br /><br /><br />bool mycmp(const Record &r1,const Record &r2){<br /><span style="white-space:pre"> </span>if(r1.total_rank <r2.total_rank)<br /><span style="white-space:pre"> </span> return true;<br /><span style="white-space:pre"> </span>else if(r1.total_rank == r2.total_rank ){<br /><span style="white-space:pre"> </span>if(strcmp(r1.ID,r2.ID) <0)<br /><span style="white-space:pre"> </span> return true; <br /><span style="white-space:pre"> </span>else<br /><span style="white-space:pre"> </span> return false; <br /><span style="white-space:pre"> </span>}else<br /><span style="white-space:pre"> </span> return false;<br />}<br /><br /><br />void mysort(Record *records,int tmp,int a[],bool global){<br /><span style="white-space:pre"> </span>int i,j;<br /><span style="white-space:pre"> </span>if(!global){<br /><span style="white-space:pre"> </span> for(i=0;i<tmp;i++){<br /><span style="white-space:pre"> </span> records[i].local_rank=1;<br /><span style="white-space:pre"> </span> for(j=100;j>records[i].score;j--)<br /><span style="white-space:pre"> </span> records[i].local_rank += a[j];<br /><span style="white-space:pre"> </span> }<br /><span style="white-space:pre"> </span>}else{<br /><span style="white-space:pre"> </span>for(i=0;i<tmp;i++){<br /><span style="white-space:pre"> </span> records[i].total_rank=1;<br /><span style="white-space:pre"> </span> for(j=100;j>records[i].score;j--)<br /><span style="white-space:pre"> </span> records[i].total_rank += a[j];<br /><span style="white-space:pre"> </span> }<br /> }<span style="white-space:pre"> </span><br />}<br /><br /><br />void display1(int &count){<br /><span style="white-space:pre"> </span>int i;<br /><span style="white-space:pre"> </span>for(i=0;i<count;i++)<br /> cout <<records[i].ID <<' '<<records[i].total_rank <<' '<br /><span style="white-space:pre"> </span><<records[i].location <<' ' <<records[i].local_rank <<endl;<br /><span style="white-space:pre"> </span><br />}<br /><br /><br />void display(int &count){<br /><span style="white-space:pre"> </span>int i;<br /><span style="white-space:pre"> </span>cout <<"*************************************************" <<endl;<br /><span style="white-space:pre"> </span>for(i=0;i<count;i++)<br /> cout <<records[i].ID <<'\t' <<records[i].score <<'\t' <<records[i].location <<'\t' <<records[i].local_rank <<endl;<br /><span style="white-space:pre"> </span>cout <<"************************************************" <<endl;<br />}<br /><br /><br />int main()<br />{<br /><span style="white-space:pre"> </span>int N;<br /><span style="white-space:pre"> </span>int stis_local[105];<br /><span style="white-space:pre"> </span>int stis_total[105];<br /><span style="white-space:pre"> </span>memset(stis_total,0,sizeof(int)*105);<br /> int count=0;<br /> int start=count;<br /><span style="white-space:pre"> </span>cin >>N ;<br /><span style="white-space:pre"> </span>int i,j=0;<br /><span style="white-space:pre"> </span>while(j<N){<br /><span style="white-space:pre"> </span>int number,score;<br /><span style="white-space:pre"> </span>cin >>number;<br /><span style="white-space:pre"> </span>memset(stis_local,0,sizeof(int)*105);<br /><span style="white-space:pre"> </span>for(i=0;i<number;i++){<br /><span style="white-space:pre"> </span>cin >>records[count].ID >>score;<br /><span style="white-space:pre"> </span>records[count].score =score;<br /><span style="white-space:pre"> </span>records[count].location = j+1;<br /><span style="white-space:pre"> </span>stis_local[score]++;<br /><span style="white-space:pre"> </span>stis_total[score]++;<br /><span style="white-space:pre"> </span>count++;<br /><span style="white-space:pre"> </span>}<br /><span style="white-space:pre"> </span>mysort(records+start,number,stis_local,false);<br /><span style="white-space:pre"> </span>start =count;<br /><span style="white-space:pre"> </span>j++;<br /><span style="white-space:pre"> </span>}<br />//<span style="white-space:pre"> </span>display(count);<br /><span style="white-space:pre"> </span>mysort(records,count,stis_total,true);<br />// display1(count);<br /><span style="white-space:pre"> </span>sort(records,records+count,mycmp);<br /> <br /> cout <<count <<endl;<br /> display1(count);<br /><span style="white-space:pre"> </span>return 0;<br /><span style="white-space:pre"> </span><br />}<br /><br /><br /><br /></p>