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. 将某个MySQL库中的UTF8字符列都转成GBK格式

    DELIMITER $$ DROP PROCEDURE IF EXISTS `dba`.`Proc_ChangeCharacter2GBK`$$ CREATE DEFINER=`root`@`%` P ...

  2. List接口实现类-ArrayList、Vector、LinkedList集合深入学习以及源代码解析

    学习List接口实现类 ArrayList  Vector  LinkedList List接口的实现类中最经常使用最重要的就是这三个:ArrayList.Vector.LinkedList. JDK ...

  3. c++ split模板实现

    模板实现,重载+6: template<typename _Elem, typename _Fty> inline void split(const _Elem* s, const _El ...

  4. hdoj 1286 找新朋友 【数论之欧拉函数】

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. 重操JS旧业第五弹:函数

    函数在任何编程语言中起着非常重要的位置,因为他是功能的最小单元,在js中函数是一种类型 Function 1 申明与定义 显示声明:function cc(){};函数名其实是函数的一个指针,函数名某 ...

  6. JSP:JAVA Bean在JSP中的运用

    目录结构,如图: index.jsp <%@ page language="java" import="java.util.*" pageEncoding ...

  7. Microsoft office PPT 2007 保存时速度慢(整理自网上)

    问题描述: XP sp3上运行PPT2007,当需要保存文件时,发现竟然需要近1分钟才能保存完毕,其间可能会出现“瘟都死沙漏”来提示你正在保存. 这简直慢到过分慢到无法容忍,一开始以为是ppt文件过大 ...

  8. 大话项目管理工具之Confluence篇

    前言 前面的两篇文章,讲的都是代码层次上的项目管理工具.这篇文章打算介绍一下关于知识管理的工具,当然,它也属于项目管理中的一部分.说到知识管理,你想到了什么呢?织网?找节点?不错,这是个人的知识管理. ...

  9. js基础语法(一)

    学习网站参考:http://www.w3school.com.cn/ 写入html输出: document.write('test out put'); 例子: http://www.w3school ...

  10. 与众不同 windows phone (29) - Communication(通信)之与 OData 服务通信

    原文:与众不同 windows phone (29) - Communication(通信)之与 OData 服务通信 [索引页][源码下载] 与众不同 windows phone (29) - Co ...