PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】
2024-10-18 23:29:32
题目链接
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);
}
}
最新文章
- CentOS 7 防火墙 firewall 的使用
- 揭秘 typedef四用途与两陷阱[转]
- 【代码升级】【iCore3 双核心板】例程二十八:FSMC实验——读写FPGA
- SpringMVC中使用DWR
- 在Android软按键中添加Menu键
- Jquery库及其他库之间的$命名冲突解决办法
- POJ 3525 Most Distant Point from the Sea
- 谈论json - json经常使用的功能
- AppiumDriver java部分api
- Cocos2d-x数据持久-变更数据
- PAT (Advanced Level) 1012. The Best Rank (25)
- node.js平台下的mysql数据库配置及连接
- 蓝桥杯- 移动距离-java
- 聚类之dbscan算法
- 介绍Docker容器
- MyISAM与InnoDB的区别是什么?
- selenium对百度进行登录注销
- CAS (多线程保证原子性)
- JQuery Deferred 对象
- bzoj 4137 [FJOI2015]火星商店问题——线段树分治+可持久化01trie树
热门文章
- PHP 5.4 中经 htmlspecialchars 转义后的中文字符串为空的问题
- yield理解
- HPU 3639--Hawk-and-Chicken【SCC缩点反向建图 &;amp;&;amp; 求传递的最大值】
- NOIP 2014 D2T3 解方程 Hash大法好
- nodejs session 设计
- 【音乐App】—— Vue-music 项目学习笔记:用户个人中心开发
- Web自动化测试框架改进
- Command terminated by signal 11
- JAVA学习第十四课(接口:implements及其基本应用)
- 在linux oracle 10g/11g x64bit环境中,goldengate随os启动而自己主动启动的脚本