PAT(甲级)1025

1025. PAT Ranking (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 85
Sample 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 3

1234567890011 9 2 4

#include
#include
#include
#define SIZE 30009

//where is the bug??  should be taken care why conting method can not 
//approved this time?
//
//FOUND THE BUG!!! THE RESULT OF STRCMP IS *P1-*P2 WHERE THE VALUE TO 
//BE COMPARED ARE DIFFERENT,NOT JUST 1 OR -1, IT MAY BE -2 5 ETC.
/
using namespace std;


struct Record{
Record();
char ID[16];
int score;
int location;
int local_rank;
int total_rank;
};


Record::Record(){
*ID='\0';
score = 0;
location = 0;
local_rank =0;
total_rank =0;
}


Record records[SIZE];


bool mycmp(const Record &r1,const Record &r2){
if(r1.total_rank    return true;
else if(r1.total_rank == r2.total_rank ){
if(strcmp(r1.ID,r2.ID) <0)
   return true; 
else
   return false;  
}else
   return false;
}


void mysort(Record *records,int tmp,int a[],bool global){
int i,j;
if(!global){
   for(i=0;i    records[i].local_rank=1;
   for(j=100;j>records[i].score;j--)
       records[i].local_rank += a[j];
   }
}else{
for(i=0;i    records[i].total_rank=1;
   for(j=100;j>records[i].score;j--)
       records[i].total_rank += a[j];
  }
    }
}


void display1(int &count){
int i;
for(i=0;i        cout < <
}


void display(int &count){
int i;
cout <<"*************************************************" < for(i=0;i        cout < cout <<"************************************************"  <}


int main()
{
int N;
int stis_local[105];
int stis_total[105];
memset(stis_total,0,sizeof(int)*105);
    int count=0;
    int start=count;
cin >>N ;
int i,j=0;
while(j int number,score;
cin >>number;
memset(stis_local,0,sizeof(int)*105);
for(i=0;i cin >>records[count].ID  >>score;
records[count].score =score;
records[count].location = j+1;
stis_local[score]++;
stis_total[score]++;
count++;
}
mysort(records+start,number,stis_local,false);
start =count;
j++;
}
// display(count);
mysort(records,count,stis_total,true);
//    display1(count);
sort(records,records+count,mycmp);
    
    cout <    display1(count);
return 0;

}



你可能感兴趣的:(PAT(甲级))