1. 在排序的过程中,注意边界的处理(小于、小于等于)

2. 对于B-level,这题是比較麻烦一些了。

源代码:

#include <cstdio>
#include <vector>
#include <algorithm> using namespace std; struct People
{
int m_id;
int m_virtue;
int m_talent;
People(int id, int virtue, int talent): m_id(id), m_virtue(virtue), m_talent(talent) {}
void print()
{
printf("%08d %d %d\n", m_id, m_virtue, m_talent);
}
friend bool operator< (const People& a, const People& b)
{
if (a.m_virtue+a.m_talent != b.m_virtue+b.m_talent)
{
return a.m_virtue+a.m_talent > b.m_virtue+b.m_talent;
} else if (a.m_virtue != b.m_virtue)
{
return a.m_virtue > b.m_virtue;
} else
{
return a.m_id < b.m_id;
}
}
}; vector<People> sage, noble_man, fool_man, small_man;
int n, l, h;
int id, virtue, talent; int main()
{
scanf("%d%d%d", &n, &l, &h);
for (int i = 0; i < n; ++ i)
{
scanf("%d%d%d", &id, &virtue, &talent);
if (virtue < l || talent < l)
{
continue;
} else if (virtue >= h && talent >= h)
{
sage.push_back( People(id, virtue, talent) );
} else if (virtue >= h)
{
noble_man.push_back( People(id, virtue, talent) );
} else if (virtue >= talent)
{
fool_man.push_back( People(id, virtue, talent) );
} else
{
small_man.push_back( People(id, virtue, talent) );
}
} sort(sage.begin(), sage.end());
sort(noble_man.begin(), noble_man.end());
sort(fool_man.begin(), fool_man.end());
sort(small_man.begin(), small_man.end()); printf("%d\n", sage.size() + noble_man.size() + fool_man.size() + small_man.size());
for (size_t i = 0; i < sage.size(); ++ i)
{
sage[i].print();
}
for (size_t i = 0; i < noble_man.size(); ++ i)
{
noble_man[i].print();
}
for (size_t i = 0; i < fool_man.size(); ++ i)
{
fool_man[i].print();
}
for (size_t i = 0; i < small_man.size(); ++ i)
{
small_man[i].print();
} return 0;
}

PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)的更多相关文章

  1. PAT 1062 Talent and Virtue[难]

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  2. 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise

    题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chine ...

  3. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  4. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  5. PAT乙级 1015. 德才论 (25)

    1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Li 宋代史学家司马光在<资治通鉴&g ...

  6. 【PAT】1015 德才论 (25)(25 分)

    1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得 ...

  7. pat 乙级 1015. 德才论 (25) c++

     http://39.106.25.239 个人网站 欢迎访问 交流 1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Sta ...

  8. PAT Basic 1015 德才论 (25 分)

    宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...

  9. pat 1062. Talent and Virtue (25)

    难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...

随机推荐

  1. 七牛用户如何将视频转码成普清高清来适应不同的手机端或者web端

    Qiniu 七牛问题解答 非常多人会用到七牛视频转码问题,要将视频转码成适用于各种终端的视频,也有的用户对转码服务的码率,帧率,分辨率等理解不多.不知道该怎样设置这些參数.以下我给大家科普一下. 问题 ...

  2. Windows Service的安装卸载 和 Service控制

    原文 Windows Service的安装卸载 和 Service控制 本文内容包括如何通过C#代码安装Windows Service(exe文件,并非打包后的安装文件).判断Service是否存在. ...

  3. 基于visual Studio2013解决面试题之0804复杂链表

     题目

  4. oracle维护表空间和数据文件

    1:重要参考 wiki 2: oracle doc 表空间参考 3:来自dba-oracle的参考 26,27,28,29 一:oracle 表空间概念 表空间是联系数据库的物理磁盘(数据文件)和逻辑 ...

  5. MyBatis简单的增删改查以及简单的分页查询实现

    MyBatis简单的增删改查以及简单的分页查询实现 <? xml version="1.0" encoding="UTF-8"? > <!DO ...

  6. MSSQL - 用GUID值来完成数据表行标识

    地址:http://www.cnblogs.com/huangfr/archive/2012/03/28/2420780.html [Guid] [uniqueidentifier] NOT NULL ...

  7. 如何将自定义标签封装成一个Jar包

    当我们在一个web应用中开发好一些自定义标签的时候,这些自定义标签通常有标签处理器Java类,和一个描述这些标签tld文件,如果我们想在以后别的web工程中还能用上这些标签,可以将这些自定义标签封装在 ...

  8. C++ overloading contructor

     // overloading class constructors #include <iostream> using namespace std; class Rectangle ...

  9. Error: 17053 LogWriter: Operating system error 21(The device is not ready.)

    今天在Detach数据库的时候出现错误,运行DBCC CHECKDB从SQL Server error log中看到下面的信息: Error: 17053, Severity: 16, State: ...

  10. POJ 2112 Optimal Milking【网络流+二分+最短路】

    求使所有牛都可以被挤牛奶的条件下牛走的最长距离. Floyd求出两两节点之间的最短路,然后二分距离. 构图: 将每一个milking machine与源点连接,边权为最大值m,每个cow与汇点连接,边 ...