【C++】PAT(advanced level)1025. PAT Ranking (25)*

来源:互联网 发布:淘宝店服装拍摄 编辑:程序博客网 时间:2024/05/17 22:55

1025. PAT Ranking (25)

时间限制
200 ms
内存限制
32000 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:
251234567890001 951234567890005 1001234567890003 951234567890002 771234567890004 8541234567890013 651234567890011 251234567890014 1001234567890012 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
1.只过了两个测试点
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<vector>#include<map>#include<iomanip>using namespace std;struct STU{char name[13];int grade;int localRank;int list;};bool cmp(STU a,STU b){if(a.grade>b.grade){return true;}else if(a.grade==b.grade){return strcmp(a.name,b.name)<0;}else{return false;}}int main(){freopen("in.txt","r",stdin);int N;vector<STU> s;while(cin>>N){int n=N;int loc=0;//位置while(n--){int K,k;cin>>K;k=K;while(k--){char sn[13];int rk;scanf("%s%d",&sn,&rk);STU sdemo;strcpy(sdemo.name,sn);sdemo.grade=rk;sdemo.list=N-n;s.push_back(sdemo);}//cout<<s.end()-s.begin();sort(s.begin()+loc,(s.begin()+loc+K),cmp);//sortint i,itemp;int curtemp=-1;for(i=0;i<K;i++){if(curtemp==s[loc+i].grade){;}else{itemp=i+1;}curtemp=s[loc+i].grade;s[loc+i].localRank=itemp;}loc=K;}sort(s.begin(),s.end(),cmp);int i,itemp;int curtemp=-1;cout<<s.size();for(int i=0;i<s.size();i++){if(curtemp==s[i].grade){;}else{itemp=i+1;}curtemp=s[i].grade;printf("\n%s %d %d %d",s[i].name,itemp,s[i].list,s[i].localRank);}}system("pause");return 0;}

0 0
原创粉丝点击