1025. PAT Ranking (25)
2016-07-06 15:07
344 查看
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:
Sample Output:
给出n个考场,每个考场有若干个学生,求出总的学生数,以及按照全部学生的成绩进行排序,输出学生的学号,总排名,考场号和地方排名。
1.用结构体表示学生的信息,对于每个考场,输入每个学生的学号,考场号和成绩;
2.用sort按照成绩排序;
3.输出结果,注意分数一样的排名一样,这里求地方排名要折腾一下,用三个数组维护地方的当前最后排名,地方当前排名最后的分数和地方当前访问过的人数,通过这三个数组得到每个人的地方排名,然后输出结果。
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct testee
{
string id;
int location;
int score;
};
bool cmp(const testee &t1,const testee &t2)
{
if(t1.score!=t2.score) return t1.score>t2.score;
else return t1.id<t2.id;
}
int main()
{
int n;
cin>>n;
vector<testee>testees;
for(int i=1;i<=n;i++)
{
int k;
cin>>k;
for(int j=1;j<=k;j++)
{
testee t;
t.location=i;
cin>>t.id>>t.score;
testees.push_back(t);
}
}
sort(testees.begin(),testees.end(),cmp);
int m=testees.size();
cout<<m<<endl;
vector<int>local_rank(n+1,1);
vector<int>score(n+1,1000);
vector<int>count(n+1,1);
int rank=1;
//cout<<testees[0].id<<" 1 "<<testees[0].location<<" 1"<<endl;
for(int i=0;i<m;i++)
{
int loc=testees[i].location,lrank;
if(i==0) rank=1;
else if(testees[i].score<testees[i-1].score) rank=i+1;
if(testees[i].score<score[loc])
{
lrank=local_rank[loc]=count[loc];
score[loc]=testees[i].score;
}
else
{
lrank=local_rank[loc];
}
count[loc]++;
cout<<testees[i].id<<" "<<rank<<" "<<testees[i].location<<" "<<lrank<<endl;
}
}
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
给出n个考场,每个考场有若干个学生,求出总的学生数,以及按照全部学生的成绩进行排序,输出学生的学号,总排名,考场号和地方排名。
1.用结构体表示学生的信息,对于每个考场,输入每个学生的学号,考场号和成绩;
2.用sort按照成绩排序;
3.输出结果,注意分数一样的排名一样,这里求地方排名要折腾一下,用三个数组维护地方的当前最后排名,地方当前排名最后的分数和地方当前访问过的人数,通过这三个数组得到每个人的地方排名,然后输出结果。
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct testee
{
string id;
int location;
int score;
};
bool cmp(const testee &t1,const testee &t2)
{
if(t1.score!=t2.score) return t1.score>t2.score;
else return t1.id<t2.id;
}
int main()
{
int n;
cin>>n;
vector<testee>testees;
for(int i=1;i<=n;i++)
{
int k;
cin>>k;
for(int j=1;j<=k;j++)
{
testee t;
t.location=i;
cin>>t.id>>t.score;
testees.push_back(t);
}
}
sort(testees.begin(),testees.end(),cmp);
int m=testees.size();
cout<<m<<endl;
vector<int>local_rank(n+1,1);
vector<int>score(n+1,1000);
vector<int>count(n+1,1);
int rank=1;
//cout<<testees[0].id<<" 1 "<<testees[0].location<<" 1"<<endl;
for(int i=0;i<m;i++)
{
int loc=testees[i].location,lrank;
if(i==0) rank=1;
else if(testees[i].score<testees[i-1].score) rank=i+1;
if(testees[i].score<score[loc])
{
lrank=local_rank[loc]=count[loc];
score[loc]=testees[i].score;
}
else
{
lrank=local_rank[loc];
}
count[loc]++;
cout<<testees[i].id<<" "<<rank<<" "<<testees[i].location<<" "<<lrank<<endl;
}
}
相关文章推荐
- 在命令行用 sort 进行排序
- Linux Shell - 如何使用sort与uniq命令删除重复的文本行
- Redis sort 排序命令详解
- 批处理命令教学之字符串排序(sort)
- mysql Sort aborted: Out of sort memory, consider increasing server sort buffer size的解决方法
- C++ 关于STL中sort()对struct排序的方法
- C#中Arraylist的sort函数用法实例分析
- Js中sort()方法的用法
- js采用concat和sort将N个数组拼接起来的方法
- 如何写JS数组sort的比较函数
- javascript中sort()的用法实例分析
- 详解Matlab中 sort 函数用法
- js模拟实现Array的sort方法
- Java数据结构及算法实例:冒泡排序 Bubble Sort
- js表数据排序 sort table data
- javascript 数组排序函数sort和reverse使用介绍
- JavaScript Table排序 2.0 (更新)
- js中数组(Array)的排序(sort)注意事项说明
- Javascript数组的排序 sort()方法和reverse()方法
- Java数据结构及算法实例:插入排序 Insertion Sort