1025 PAT Ranking

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:

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
/*
1.Clarification:
return registration_number final_rank location_number local_rank
so we need struct informations such as number,grade,final_rank,location number,local_rank
and woe use algorithm sort to sort the grade
The time cost is:
*/

#include <iostream>
#include <string>
#include <algorithm>
#include<cstring>
using namespace std;

struct student{
	char number[13];
	int grade;
	int final_rank;
	int location_number;
	int local_rank;
}stu[31000];

bool cmp(student a,student b){
	if(a.grade!=b.grade)
	{
		return a.grade>b.grade;
	 }
	 else
	 {
	 	return strcmp(a.number,b.number)<0;
	 }
} 

int main()
{
//	freopen("C://坚果云//算法//PATA1025in.txt","r",stdin);
//	freopen("C://坚果云//算法//PATA1025out.txt","w",stdout);
	int N,K,num=0;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&K);
		for(int j=0;j<K;j++)
		{
			scanf("%s %d",&stu[num].number,&stu[num].grade);
			stu[num].location_number = i;
			num++;
		}
		sort(stu+num-K,stu+num,cmp);
		stu[num-K].local_rank = 1;
		for(int t=num-K+1;t<num;t++)
		{
			if(stu[t].grade!=stu[t-1].grade)
			{
				stu[t].local_rank=t+1-num+K;
			}
			else
			{
				stu[t].local_rank = stu[t-1].local_rank;
			}
		 }
	}
	sort(stu,stu+num,cmp);
	printf("%d\n",num);
	int r=1;
	for(int i=0;i<num;i++)
	{
		if(i>0&&stu[i].grade!=stu[i-1].grade)
		{
			r=i+1;
		}
		printf("%s ",stu[i].number);
		printf("%d %d %d\n",r,stu[i].location_number,stu[i].local_rank);
	}

//	fclose(stdin);
//	fclose(stdout);
	return 0;
 } 

PAT甲级——1025 PAT Ranking的更多相关文章

  1. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  2. PAT 甲级 1025.PAT Ranking C++/Java

      Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...

  3. PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

    题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...

  4. 【PAT】1025. PAT Ranking (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...

  5. PAT 甲级 1141 PAT Ranking of Institutions

    https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...

  6. PAT甲级——A1025 PAT Ranking

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  7. PAT甲级1075 PAT Judge

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032 题意: 有m次OJ提交记录,总共有k道 ...

  8. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

    1075 PAT Judge (25分)   The ranklist of PAT is generated from the status list, which shows the scores ...

  9. PAT甲级——A1075 PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

随机推荐

  1. DRF框架之DRF的引入

    DRF框架是python_web中采用前后端分离开发模式的框架,其处理JSON数据是最快的. 通过DRF框架,我们后端程序员只需要拼接并响应JSON数据即可,并且数据复用性高适用于浏览器端.APP端等 ...

  2. 最短路———Floyd算法

    C - 六度分离 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  3. i春秋-web- 爆破2

    题目:flag不在变量中. 打开链接: <?php include "flag.php"; $a = @$_REQUEST['hello']; eval( "var ...

  4. idea新建文件模板 (以xml文件为例)

    https://blog.csdn.net/li1325169021/article/details/93158207 偷个懒

  5. Java中常用的API(一)——Object

    概述 如果要问Java为什么是用起来非常舒服的语言,那很大一部分的功劳就是JavaAPI的.API定义了许多封装好的类和方法供我们使用,来处理特定的问题,所以学习常用的API是非常重要的. 同时,面向 ...

  6. VMware vSphere虚拟化-VMware ESXi 5.5组件添加本地磁盘--虚拟机扩容

    本地存储器可以是位于ESXi主机内部的内部硬盘,也可以是位于主机之外并直接通过SAS或者SATA等协议连接在主机上的外部存储系统.本地存储不需要存储网络即可与主机进行通信,只需要一根连接到存储单元的电 ...

  7. 关于PIL库Image模块的一些测试代码

    为了加深理解,写了一些代码测试,在这里记录一下吧: 关于图片的模式问题,之前做过笔记,有“1”,“L”,"P","RGB","RGBA",& ...

  8. Java web:html+css(2020.1.5)

    html 1.font-size中1em=16px 2.html中font不要使用 3.链接标签<a></a>禁止下划线样式设置 <style> a{ color: ...

  9. Go-map-字符串-指针-结构体

    Maps 什么是 map ? 类似Python中的字典数据类型,以k:v键值对的形式. map 是在 Go 中将值(value)与键(key)关联的内置类型.通过相应的键可以获取到值. 如何创建 ma ...

  10. Python—构造单向链表数据类型

    # _*_ coding=utf-8 _*_ class Node: """ 创建链表的属性 """ def __init__(self, ...