【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)
题意:
输入一个正整数N(N<=100),表示接下来有N组数据。每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成。求输出所有考生的数量并且按照考生在全体中的成绩排名以及ID的字典序输出ID和名词,并标注考生所在的考场编号以及他在考场中的排名。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
typedef struct anss{
string s;
int final_rank;
int local_num;
int local_rank;
};
anss ans[];
typedef struct testee{
string num;
int score;
};
testee t[][];
testee a[];
bool cmp(testee a,testee b){
return a.score>b.score;
}
bool cmp1(anss a,anss b){
if(a.final_rank!=b.final_rank)
return a.final_rank<b.final_rank;
return a.s<b.s;
}
int cnt[];
int main(){
int n;
cin>>n;
int tt=;
int tot=;
for(int i=;i<=n;++i){
int m;
cin>>m;
cnt[i]=m;
for(int j=;j<=m;++j){
string s;
int x;
cin>>s>>x;
t[i][j].num=s;
t[i][j].score=x;
a[++tot].num=s;
a[tot].score=x;
mp[s]=++tt;
ans[tt].s=s;
ans[tt].local_num=i;
}
}
for(int i=;i<=n;++i){
sort(t[i]+,t[i]++cnt[i],cmp);
int no=;
int tmp=;
ans[mp[t[i][].num]].local_rank=++no;
for(int j=;j<=cnt[i];++j)
if(t[i][j].score!=t[i][j-].score){
ans[mp[t[i][j].num]].local_rank=++no;
tmp=no;
}
else{
ans[mp[t[i][j].num]].local_rank=tmp;
++no;
}
}
int sum=;
for(int i=;i<=n;++i)
sum+=cnt[i];
sort(a+,a++sum,cmp);
int no=;
int tmp=;
ans[mp[a[].num]].final_rank=++no;
for(int i=;i<=sum;++i)
if(a[i].score!=a[i-].score){
ans[mp[a[i].num]].final_rank=++no;
tmp=no;
}
else{
ans[mp[a[i].num]].final_rank=tmp;
++no;
}
sort(ans+,ans++sum,cmp1);
cout<<sum<<"\n";
for(int i=;i<=sum;++i)
cout<<ans[i].s<<" "<<ans[i].final_rank<<" "<<ans[i].local_num<<" "<<ans[i].local_rank<<"\n";
return ;
}
【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)的更多相关文章
- PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- GO学习-(38) Go语言结构体转map[string]interface{}的若干方法
结构体转map[string]interface{}的若干方法 本文介绍了Go语言中将结构体转成map[string]interface{}时你需要了解的"坑",也有你需要知道的若 ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
随机推荐
- django urls.py 中的name 使用方法
使用场景: 当我们在url的时候,一般情况下都是使用很明确的url地址.如在网页里面使用<a href="/login">登录</a>.像这样的链接有很 多 ...
- JAVA(5)之关于main函数的默认放置位置
Eclipse默认主程序入口 Public class 的main函数 package com.study; public class Test { public static void main(S ...
- Java面向对象编程 -4.2
声明static定义方法 这个时候对于程序而言方法就有了两种:static方法 非static方法. 这两个方法之间在调用上就有了限制: static方法只允许调用static属性或static方法 ...
- java用JSONObject生成json
Json在前后台传输中,是使用最多的一种数据类型.json生成的方法有很多,自己只是很皮毛的知道点,用的时候,难免会蒙.现在整理下 第一种: import net.sf.json.JSONArray; ...
- python、js实现WGS84、高德(火星)、百度坐标转换
在日常工作学习中常会涉及到WGS84.高德(火星/谷歌).百度三种空间坐标系的坐标转换,本文将通过python.js两种语言实现坐标系的转换. 坐标系说明: wgs84:为一种大地坐标系,也是目前广泛 ...
- 计算机二级-C语言-程序填空题-190117记录-对文件的处理,复制两个文件,往新文件中写入数据。
//给定程序的功能是,调用函数fun将指定源文件中的内容赋值到指定目标文件中,复制成功时函数返回1,失败时返回0,把复制的内容输出到终端屏幕.主函数中源文件名放在变量sfname中,目标文件名放在变量 ...
- WinForm开发(2)——DataGridView控件(2)——C# dataGridview控件,怎么获取行数
dataGridView1.Rows.Count;//所有行数dataGridView1.RowCount;//可见行数
- 样式计算的几种方式与兼容写法:getComputedStyle¤tStyle&style
window.getComputedStyle(element,[string]) 1参为需要获取样式的元素,2参指定伪元素字符串(如“::after”,不需要则为null),设置2参可获取eleme ...
- mysql 默认信息
泰基MYSQL默认信息 登录名1-------默认用户 名字:root 密码:123 登录名2-------APP对应的数据库 名字:hotekey 密码:8888
- formValidation单个输入框值改变时校验
$("#tv_form").data("formValidation").updateStatus("pay.vcAmount", &qu ...