题目链接

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. SCP和SFTP相同点和区别

    都是使用SSH协议来传输文件的.不用说文件内容,就是登录时的用户信息都是经过SSH加密后才传输的,所以说SCP和SFTP实现了安全的文件传输. SCP和CP命令相似,SFTP和FTP的使用方法也类似. ...

  2. 《转》 在C++中使用TinyXML2解析xml

    读取和设置xml配置文件是最经常使用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,由于它的API接口和Java的十分类似.面向对象性非常好.       TinyX ...

  3. C# DateTime和String(转)

    http://www.cnblogs.com/Pickuper/articles/2058880.html C#语言之“string格式的日期时间字符串转为DateTime类型”的方法 方法一:Con ...

  4. 让heigh:100%起作用

    如何让 height:100%; 起作用 http://www.webhek.com/css-100-percent-height     当你设置一个页面元素的高度(height)为100%时,期望 ...

  5. hint指定index的深入理解

    http://czmmiao.iteye.com/blog/1480247创建一个表,含有位图index和b-tree index SQL> create table t as select o ...

  6. 字符串(string)操作的相关方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. Leetcode Array 16 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  8. 转:PCIe基础知识

    PCIe基础知识   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zqixiao_09/article/details/51842542 PCIe ...

  9. 为备考二级C语言做的代码练习---辅导资料《C语言经典编程282例》--(1)

    因为二级考试的时候用的C语言编译器是VC++6.0 真是日了狗了 用这个编译器 这是我第2个C编译器吧,第一个用的是啊哈C编译器..第二个是VS++6.0 然后在win下用VS2013感觉挺不错的 毕 ...

  10. dede列表页调用文章,其实是所有页面都可以调用,第一次应用sql标签

    {dede:sql sql="SELECT aid,typeid,body,userip FROM `#@__addonarticle` where aid='6' or aid='7' o ...