PAT甲级1025

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 (≤), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤), 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<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
struct stu
{
	int sor;
	string id;
	int score;
	int flag;
	bool operator < (const stu & a)
	{
		if (score != a.score)
			return score > a.score;
		else
			return id < a.id;
	}
}buf;
int main()
{
	FILE* stream1;
	freopen_s(&stream1, "input.txt", "r", stdin);
	int n;
	while (cin >> n)
	{
		int k;
		vector<stu>s;
		int flag = 0;
		while (n--)
		{
			cin >> k;
			flag++;
			vector<stu>v;
			while (k--)
			{
				cin >> buf.id >> buf.score;
				buf.flag = flag;
				v.push_back(buf);
			}
			sort(v.begin(), v.end());
			v[0].sor = 1; s.push_back(v[0]);
			for (int i = 1; i <v.size(); i++)
			{
				if ( v[i].score == v[i - 1].score)
					v[i].sor = v[i - 1].sor;
				else
					v[i].sor = i+1;
				s.push_back(v[i]);
			}
		}
		sort(s.begin(), s.end());
		cout << s.size() <<endl;
		int r = 1;
		cout << s[0].id << " " << r << " " << s[0].flag << " " << s[0].sor << endl;
		for (int i = 1; i < s.size(); i++)
		{
			if (s[i].score != s[i - 1].score)
				r = i + 1;
			cout << s[i].id << " " << r << " " << s[i].flag << " " << s[i].sor << endl;
		}
	}
	return 0;
}
不想定义主程序外的结构体大数组,就用了主程序内的两个VECTOR,
代码学习笔记 文章被收录于专栏

学习笔记,pat,牛客

全部评论

相关推荐

卖挂面鸡蛋不锈钢盆:top2 就发面试的年代已经一去不复发了
投递快手等公司10个岗位
点赞 评论 收藏
分享
牛客小菜鸡66:boss里面,招人的叫老板,找工作的叫牛人
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务