1025. PAT Ranking (25)

来源:互联网 发布:问道九游端口 编辑:程序博客网 时间:2024/06/06 03:53
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.


IDEA

1.成绩相同,排名相同,需要处理

2.成绩相同,reg_number从小到大排


CODE

#include<iostream>#include<cstring>#include<vector>#include<algorithm>using namespace std;struct Stu{string reg_number;int loc_number;int score;int final_rank;int loc_rank;};int cmp(Stu stu1,Stu stu2){if(stu1.score==stu2.score){return stu1.reg_number<stu2.reg_number;}return stu1.score>stu2.score;}void locRank(vector<Stu> &v,int k){for(int i=0;i<k;i++){if(i==0){v[i].loc_rank=1;}else if(v[i].score==v[i-1].score){v[i].loc_rank=v[i-1].loc_rank;}else{v[i].loc_rank=i+1;}}}void finalRank(vector<Stu> &v,int k){for(int i=0;i<k;i++){if(i==0){v[i].final_rank=1;}else if(v[i].score==v[i-1].score){v[i].final_rank=v[i-1].final_rank;}else{v[i].final_rank=i+1;}}}int main(){int n;cin>>n;int count=0;vector<Stu> vec;for(int i=0;i<n;i++){int k;cin>>k;count+=k;if(!k){continue;}vector<Stu> v;for(int j=0;j<k;j++){Stu stu;cin>>stu.reg_number>>stu.score;stu.loc_number=i+1;stu.final_rank=0;stu.loc_rank=0;v.push_back(stu);}sort(v.begin(),v.end(),cmp);locRank(v,k);for(int j=0;j<k;j++){vec.push_back(v[j]);}}cout<<count<<endl;if(!count){return 0;}sort(vec.begin(),vec.end(),cmp);finalRank(vec,count);vector<Stu>::iterator it;for(it=vec.begin();it!=vec.end();it++){cout<<(*it).reg_number<<" "<<(*it).final_rank<<" "<<(*it).loc_number<<" "<<(*it).loc_rank<<endl;}return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 三岁宝宝不说话怎么办 六个月宝宝粘人怎么办 11个月宝宝粘人怎么办 一岁宝宝脸冻了怎么办 2个月宝宝粘人怎么办 8个月宝宝粘人怎么办 9个月宝宝粘人怎么办 8个月婴儿粘人怎么办 4个月宝宝粘人怎么办 7个月宝宝粘人怎么办 8个月孩子太粘人怎么办 7个月宝宝太粘人怎么办 两岁宝宝粘人怎么办 孩子屁股被打了怎么办 长期被骂的孩子怎么办 儿童感冒咳嗽怎么办最有效 打了排卵针不排卵怎么办 孩孑上课不专心怎么办 4岁上课不听讲怎么办 孩子上课不认真听讲怎么办 孩子做什么都慢怎么办 7岁上课不听讲怎么办 打孩子脸肿了怎么办 一岁宝宝太调皮怎么办 怀孕早期喝了酒怎么办 怀孕期间喝了酒怎么办 一岁宝宝多动怎么办 3岁前儿童多动症怎么办 好动症的孩子该怎么办 18个月宝宝腹泻怎么办 8个月小孩发烧怎么办 八个月大宝宝发烧怎么办 8个月宝宝拉稀水怎么办 八个月宝宝38度怎么办 8个月的宝宝发烧怎么办 八个月大的宝宝拉肚子怎么办 9孩子上课坐不住怎么办 3岁宝宝太皮怎么办 4岁的宝宝多动症怎么办 小孩好动注意力不集中怎么办 乐扣加热变形了怎么办