【C++】PAT(advanced level)1025. PAT Ranking (25)*
来源:互联网 发布:淘宝店服装拍摄 编辑:程序博客网 时间:2024/05/17 22:55
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:251234567890001 951234567890005 1001234567890003 951234567890002 771234567890004 8541234567890013 651234567890011 251234567890014 1001234567890012 85Sample 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
#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;}
- 【C++】PAT(advanced level)1025. PAT Ranking (25)*
- 【PAT Advanced Level】1025. PAT Ranking (25)
- 【PAT】【Advanced Level】1025. PAT Ranking (25)
- 1025. PAT Ranking (25) @ PAT (Advanced Level) Practise
- PAT (Advanced Level) 1025. PAT Ranking (25) 结构体排序
- 浙大 PAT Advanced level 1025. PAT Ranking (25)
- PAT (Advanced) 1025. PAT Ranking (25)
- PAT (Advanced Level) Practise 1025 PAT Ranking (25)
- PAT (Advanced Level) Practise 1025 PAT Ranking (25)
- Pat(Advanced Level)Practice--1025(PAT Ranking)
- 1025. PAT Ranking (25)【排序】——PAT (Advanced Level) Practise
- 【c++】PAT (Advanced Level)1010. Radix (25)
- 【C++】PAT(advanced level)1032. Sharing (25)
- 【C++】PAT(advanced level)1029. Median (25)
- PAT 1025. PAT Ranking (25)
- 【PAT】1025. PAT Ranking (25)
- PAT 1025. PAT Ranking (25)
- PAT 1025. PAT Ranking (25)
- 在多核通信平台上构建网络系统的几个要点
- 7 Simple Steps to Connect SQL Server Using WCF from SilverLight
- ArrayBlockingQueue调度多线程demo
- java环境变量配置
- Android 程序清单详解
- 【C++】PAT(advanced level)1025. PAT Ranking (25)*
- 多核通信
- 使用C#代码部署SharePoint 2013开发包简单总结(一)
- 关于ssh编码问题
- linux 3.11.10, mini2440, usb wifi TL-WN721 8176 ,8192cu ,os_intfs.o error1
- android hanlder loop message的理解
- hive修改表模式
- ADB server didn't ACK, failed to start daemon
- The Elements of Statistical Learning第一章翻译