1025. PAT Ranking (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

提交代码

string的相互比较:

 #include<string>
#include<iostream>
using namespace std;
int main(){
//freopen("D:\\input.txt","r",stdin);
//a.compare(b)
//a>b 1
//a==b 0
//a<b -1
string a="",b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
return ;
}

比较的思想:
1.整体排序,注意成绩非升序(成绩相同时,编号升序)。

2.

localrank[i]:第i个区域当前的排名,允许成绩相同排名相同。

lastgrade[i]:第i个区域前一个排名的成绩。

localnum[i]:第i个区域已经排名的人数。

 #include<set>
#include<map>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
int localrank[],lastgrade[],localnum[];
//registration_number final_rank location_number local_rank
struct person{
string s;
int grade,localnum;
};
person per[];
bool cmp(person a,person b){
if(a.grade==b.grade){
return a.s.compare(b.s)<;
}
return a.grade>b.grade;
}
int main(){
//freopen("D:\\input.txt","r",stdin);
int n;
scanf("%d",&n);
int i,j,k,l;
per[].grade=;//哨兵
l=;
for(i=;i<=n;i++){
scanf("%d",&k);
for(j=;j<=k;j++){
cin>>per[l].s;
scanf("%d",&per[l].grade);
per[l++].localnum=i;
}
lastgrade[i]=;
}
l--;
sort(per,per+l+,cmp);
memset(localrank,,sizeof(localrank));
memset(localnum,,sizeof(localnum));
int rank;
cout<<l<<endl;
for(i=;i<=l;i++){
cout<<per[i].s<<" ";
if(per[i].grade<per[i-].grade){
rank=i;
}
cout<<rank<<" "<<per[i].localnum<<" ";
localnum[per[i].localnum]++;
if(per[i].grade<lastgrade[per[i].localnum]){
lastgrade[per[i].localnum]=per[i].grade;
localrank[per[i].localnum]=localnum[per[i].localnum];
}
cout<<localrank[per[i].localnum]<<endl;
}
return ;
}

pat1025. PAT Ranking (25)的更多相关文章

  1. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

  2. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  3. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

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

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

  5. 1025. PAT Ranking (25)

    题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology ...

  6. 1025 PAT Ranking (25)(25 point(s))

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

  7. PAT A1025 PAT Ranking(25)

    题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...

  8. 1025 PAT Ranking (25 分)

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

  9. 1025 PAT Ranking (25分) 思路分析 +满分代码

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

随机推荐

  1. 控制某个panel的display样式

    "我想在onload方法里把panel的 style 里的 display 属性变成 none.我的页面由于有一些脚本,触发某些事件之后还想显示这个panel,不想用Panel3.Visib ...

  2. 浅谈UBUNTU

    一 UBUNTU介绍 Ubuntu(乌班图)是一个以桌面应用为主的Linux操作系统,其名称来自非洲南部祖鲁语或豪萨语的"ubuntu"一词,意思是"人性".& ...

  3. form表单操作

    Django之Form组件 Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 简单例子  For ...

  4. [SinGuLaRiTy] 二分图&匈牙利算法

    [SinGuLaRiTY-1019] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 二分图 二分图是图论中一种特殊的图形.顾名思义,二分图G ...

  5. kuangbin专题16I(kmp)

    题目链接: https://vjudge.net/contest/70325#problem/I 题意: 求多个字符串的最长公共子串, 有多个则输出字典序最小的. 思路: 这里的字符串长度固定为 60 ...

  6. python web开发之flask框架学习(2) 加载模版

    上次学习了flask的helloword项目的创建,这次来学习flask项目的模版加载: 第一步:创建一个flask项目 第二步:在项目目录的templates文件夹下创建一个html文件 第三步: ...

  7. python3查询mysql数据

    python3不支持MySQLdb,代替的是import pymysql 连接数据库查表: import pymysqlconn= pymysql.connect( host='xx.xx.xx.xx ...

  8. USACO 1.1.1 YOUR RIDE IS HERE

    众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走.他们为每 ...

  9. 关于在多个UItextield切换焦点

    本人对于应用的完美用户体验是这样认为:当一个应用是迎合用户习惯 ,并且在人机交互之中降低用户的学习成本 ,由于应用和人的思维方向一致时,就会有共鸣,这对于程序设计是有益的,因为只要愿意去改变总有优雅的 ...

  10. centos下yum搭建安装linux+apache+mysql+php环境教程

    我们利用linux系统中yum安装Apache+MySQL+PHP是非常的简单哦,只需要几步就可以完成,具体如下: 一.脚本YUM源安装: 1.yum install wget             ...