题目链接

https://www.patest.cn/contests/pat-b-practise/1085

思路

结构体排序

要注意几个点

它的加权总分 是 取其整数部分

也就是 要 向下取整

然后这个操作要在排序操作之前

不能在输出的时候 进行

不然最后一个测试点 过不了

因为 假如

有两个学校的分数 分别是

195.1 195.2

如果排序按照这个排 就是 195.1 < 195.2

就会按照 总分来排

但实际上 向下取整之后 都是195 所以应该按照 考生人数 或者是单位码来排的

还有要注意的是 单位码 是小写

以及 排名的方式

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7; struct Node
{
string name;
int tot;
double score;
int s;
}; bool comp(Node x, Node y)
{
if (x.s == y.s)
{
if (x.tot == y.tot)
return x.name < y.name;
else
return x.tot < y.tot;
}
return x.s > y.s;
} int main()
{
int n;
cin >> n;
map <string, Node> m;
string id, school;
int score;
for (int i = 0; i < n; i++)
{
cin >> id >> score >> school;
int len = school.size();
for (int j = 0; j < len; j++)
if (school[j] >= 'A' && school[j] <= 'Z')
school[j] += 32;
m[school].tot++;
m[school].name = school;
if (id[0] == 'A')
m[school].score += score;
else if (id[0] == 'B')
m[school].score += score * 1.0 / 1.5;
else
m[school].score += score * 1.5;
}
map <string, Node>::iterator it;
vector <Node> ans;
for (it = m.begin(); it != m.end(); it++)
{
it->second.s = floor(it->second.score);
ans.pb(it->second);
}
sort(ans.begin(), ans.end(), comp);
int len = ans.size();
cout << len << endl;
printf("1 ");
cout << ans[0].name;
printf(" %d %d\n", ans[0].s, ans[0].tot);
int rank = 1;
for (int i = 1; i < len; i++)
{
if (ans[i].s != ans[i - 1].s)
rank = i + 1;
printf("%d ", rank);
cout << ans[i].name;
printf(" %d %d\n", ans[i].s, ans[i].tot);
}
}

PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】的更多相关文章

  1. PAT A 1022. Digital Library (30)【结构体排序检索】

    https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #incl ...

  2. PAT(B) 1085 PAT单位排行(Java:20分)

    题目链接:1085 PAT单位排行 (25 point(s)) 题目描述 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式 输入第一行给出一个正整数 N ...

  3. PAT乙级:1090危险品装箱(25分)

    PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...

  4. PAT乙级:1070 结绳 (25分)

    PAT乙级:1070 结绳 (25分) 题干 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟 ...

  5. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 第m大的身份证号码(局部排序代全局、结构体排序)

    第m大的身份证号码(点击) 时间限制: 1 Sec  内存限制: 128 MB                                                             ...

  8. 转载 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

    转载自:http://www.cnblogs.com/cj695/p/3863142.html sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在 ...

  9. 【转】 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

    sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能 ...

随机推荐

  1. eclipse运行时弹出Fail to create the Java Virtual Machine

    找到eclipse程序所在目录,在目录下找到eclipse.ini文件,打开文件将com.android.ide.eclipse.adt.package.product下的值改成128m,org.ec ...

  2. nginx 启动,重启,添加开机启动等相关命令

    nginx -t 测试 配置文件是否正确,同时可以查看配置文件路径 nginx -c /usr/local/nginx/conf/nginx.conf   启动nginx ps -ef|grep ng ...

  3. memcache 开机启动

    一. 通常:启动Memcache的服务器端的命令为:# /usr/local/bin/memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 - ...

  4. EasyMvc入门教程-基本控件说明(13)选项卡导航

    选项卡Tab导航主要用于企业页面显示不同子类或者子页面的信息内容. 先来一个基本的使用例子:代码如下: @{ var data = new List<TabItem>() { new Ta ...

  5. MongoDB下载安装測试及使用

    1.下载安装 64位:mongodb-win32-x86_64-enterprise-windows-64-2.6.4-signed.msi 余数为1的 db.collection.find({ &q ...

  6. String转Map的工具类

    借鉴代码 public class StringToMapUtil { public static Map<String, String> getValue(String param) { ...

  7. unity3D中使用Socket进行数据通信(一)

    公司今年3D产品的工作中心主要集中在提高产品深度上,通过对竞争产品的分析,发现我们的缺陷在于多人在线与后台管理部分,多人在线使用unity自带的Network能够搞定,后台部分前段时间主要研究了下Sq ...

  8. 【VBS】发邮件

    Sub SendMail(pMailFrom, pMailTo, pSubject, pMailBody, pMailSmtpServer) On Error Resume Next Dim objS ...

  9. 一款炫酷Loading动画--载入成功

    简单介绍 昨天在简书上看到一篇文章.介绍了一个载入动画的实现过程 一款Loading动画的实现思路(一) 仅仅可惜原动画是IOS上制作的.而看了一下.作者的实现思路比較复杂,于是趁着空暇写了一个And ...

  10. kettle转换之多线程

    kettle转换之多线程   ETL项目中性能方面的考虑一般是最重要的.特别是所讨论的任务频繁运行,或一些列的任务必须在固定的时间内运行.本文重点介绍利用kettle转换的多线程特性.以优化其性能. ...