PAT A1025 pat ranking

有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出

#include<iostream>
#include<string.h>
#include<algorithm>
//#include<map>

using namespace std;
struct Student
{
	char id[15];           //准考证号
	int score;            //分数
	int location_number;  //考场号
	int location_rank;  //考场内排名
} stu[30010];

bool cmp(Student a,Student b)
{
	if(a.score != b.score) return a.score> b.score; //按分数从高到底排序
	else return strcmp(a.id,b.id)<0; //分数按照准考证号从小到大排序
} 

int main()
{
	int n,k,num=0;
	cin>>n;//n为考场数
	for(int i=0;i<n;i++)
	{
		cin>>k;
		for(int j=0;j<k;j++)
		{
		cin>>stu[num].id>>stu[num].score;
		stu[num].location_number=i;
		num++;
	    }
	sort(stu + num-k,stu+num,cmp);
	stu[num-k].location_rank=1;    //对于考场的第一名rank记为1
	for(int j = num-k+1;j<num;j++)
	{
		if(stu[j].score==stu[j-1].score)
		{
			stu[j].location_rank=stu[j-1].location_rank;
		}
		else
		{
			stu[j].location_rank=j+1-(num-k);
		}
	 }
	}
	cout<<num<<endl;
	sort(stu,stu+num,cmp);
	int r=1;
	for (int i=0;i<num;i++)
	{
		if(i>0&&stu[i].score != stu[i-1].score)
		{
			r=i+1;
		}
		cout<<stu[i].id;
		cout<<r<<stu[i].location_number<<stu[i].location_rank<<endl;
	}
	return 0;
}
/*
输入样例:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
*/

  

原文地址:https://www.cnblogs.com/chuxinbubian/p/11581804.html

时间: 2024-11-07 06:58:07

PAT A1025 pat ranking的相关文章

PAT A1025 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

PAT 1075. PAT Judge (25)

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定要熟练,还有就是编译没有通过为零分,没有提交显示为"-": #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int NUM=10001

PAT甲级——A1025 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 i

【算法学习记录-排序题】【PAT A1025】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 i

PAT 1025 PAT Ranking

#include <cstdio> #include <cstdlib> #include <vector> #include <cstring> #include <queue> #include <algorithm> using namespace std; class Man { public: char id[14]; int location; int score; int local_rank; }; class Ran

【PAT A1025】部分正确-&gt;全部正确

#include <algorithm> #include <stdio.h> #include <string.h> #include <fstream> #include <iostream> #include <string.h> #include <cstring> #include <vector> using namespace std; #define maxN 105 #define manK

1141 PAT Ranking of Institutions[难]

1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist. Input Specification: Each input file contains one test

1141 PAT Ranking of Institutions PAT甲级

After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.Input Specification:Each input file contains one test case. For each case, the first line gives

ASA配置实例之NAT和PAT的地址转换(二)

ASA防火墙配置实验 实验拓扑图: 基础配置命令: ASA conf t hostname ASA int e0/0 nameif inside security-level 100 ip add 192.168.1.5 255.255.255.0 no sh int e0/1 nameif dmz security-level 50 ip add 192.168.2.5 255.255.255.0 no sh int e0/2 nameif outside security-level 0 i