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. HDU - 5036 Explosion

    Problem Description Everyone knows Matt enjoys playing games very much. Now, he is playing such a ga ...

  2. oracle 的常用语句

    第一部分 基本语法 //拼接表字段 select id   ||   'is'   ||   name from admin select * from emp where ename like '% ...

  3. ORACLE DATABASE 10G FALSHBACK 知识整理

    1.知识储备 1)    当出现介质损坏时(如数据文件丢失),任何闪回方法都毫无用处,只能执行标准的备份.还原与恢复. 2.SCN记录方法 SQL>variable x_scn number; ...

  4. Kendo UI开发教程(24): 单页面应用(二) Router 类

    Route类负责跟踪应用的当前状态和支持在应用的不同状态之间切换.Route通过Url的片段功能(#url)和流量器的浏览历史功能融合在一起.从而可以支持把应用的某个状态作为书签添加到浏览器中.Rou ...

  5. android用canvas绘制两种波纹效果

     波形效果有几种不同的呈现形式,比如从中间向四周散开的波形,也就是熟知的水涟漪:还有上下波动的曲线,像五线谱等.英文中可以称作Wave或者Ripple,所以暂且叫它们WaveView.WaveLayo ...

  6. java内存模型与线程(转) good

    java内存模型与线程 参考 http://baike.baidu.com/view/8657411.htm http://developer.51cto.com/art/201309/410971_ ...

  7. uva 11400 Problem F Lighting System Design

    紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 ...

  8. Visual Studio 控件命名规范(很详细)

    VS 控件命名规范 Type Prefix Example Array arr arrShoppingList Boolean bln blnIsPostBack Byte byt bytPixelV ...

  9. MySQL :: MySQL 5.0 Reference Manual :: 14.4 The MEMORY (HEAP) Storage Engine

    MySQL :: MySQL 5.0 Reference Manual :: 14.4 The MEMORY (HEAP) Storage Engine The MEMORY (HEAP) Stora ...

  10. hdu 1665 That Nice Euler Circuit(欧拉定理)

    输入n个点,然后从第一个点开始,依次链接点i->点i+1,最后回到第一点(输入中的点n),求得到的图形将平面分成了多少部分. 根据欧拉定理 v_num + f_num - e_num = 2可知 ...