一道关于奥运奖牌排序的题
来源:互联网 发布:学vb好还是c语言好 编辑:程序博客网 时间:2024/04/28 10:07
一道关于奥运奖牌排序的题:
忘记在哪里看到的思路:若排序有多重优先级,则从低优先级到高优先级依次排序,排完了也就是正确结果。
发现C++真是个好东西。
下面是我写的程序,没有各种非法情况的检测。
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <functional>//#include <>using namespace std;struct olympic_honor{char country[40];int gold;int silver;int tong;};bool more_gold(const struct olympic_honor &oh1,const struct olympic_honor &oh2){return oh1.gold > oh2.gold;}bool more_silver(const struct olympic_honor &oh1,const struct olympic_honor &oh2){return oh1.silver > oh2.silver;}bool more_tong(const struct olympic_honor &oh1,const struct olympic_honor &oh2){return oh1.tong > oh2.tong;}bool more_country(const struct olympic_honor &oh1,const struct olympic_honor &oh2){if(strcmp(oh1.country,oh2.country)<0)return true;else return false;}int main(){int num_country = 0;olympic_honor oh;oh.country[0] = '\0';oh.gold = 0;oh.silver = 0;oh.tong = 0;vector<olympic_honor> vec_oh; printf("Input number: \n");scanf("%d",&num_country);printf("input %d countries: \n",num_country);for(int i = 0; i < num_country; i++){scanf("%s%d%d%d",(oh.country),&(oh.gold),&(oh.silver),&(oh.tong));vec_oh.push_back(oh);}sort(vec_oh.begin(),vec_oh.end(),more_country);sort(vec_oh.begin(),vec_oh.end(),more_tong);sort(vec_oh.begin(),vec_oh.end(),more_silver);sort(vec_oh.begin(),vec_oh.end(),more_gold);for(size_t i = 0; i < vec_oh.size(); i++){printf("%s\n",vec_oh[i].country);}system("pause");return 0;}
sort(begin(),end(),规则);
0 0
- 一道关于奥运奖牌排序的题
- 奥运奖牌计数
- 奥运奖牌中文信息系统
- 07:奥运奖牌计数
- 7. 奥运奖牌计数
- 奥运奖牌榜的小调用,是新浪的。
- 一道关于排序的算法题
- 洛奇:关于古代的奖牌
- 一道关于排序的题目
- [奥运] 28届奥运会中国队奖牌一览
- 奥运奖牌中文系统(IO版)
- Olympic奖牌榜排序
- 【奥运奖牌大竞猜】CSDN网友奥运大联欢(二)
- 关于奥运的记忆
- 一道关于下标排序的金山笔试题
- 一道关于排序的面试题
- 一道可爱的排序题
- 拓扑排序的一道题
- Struts2动态方法调用,找不到Action
- Hibernate基本手法
- androi开发中,如何避免内存泄露 .
- hive参数——深入浅出学Hive
- 港媒称李心洁考虑离婚 张艾嘉对彭顺怒不可遏
- 一道关于奥运奖牌排序的题
- Windows平台下VIM环境搭建
- flash builder4.5 集成svn1.8
- Paparazzi飞控项目
- OCP 1Z0 052 89
- delphi控制Excel(二)
- 女子患异食癖11年吃下半吨墙砖 加清洁剂调味
- winxp、win2003、win7、win8通用的shellcode
- WZC框架下wifi功能的实现