老--质价比(直接sort排序)
来源:互联网 发布:中兴交换机网管软件 编辑:程序博客网 时间:2024/05/01 20:31
老--质价比
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
给出n件物品,每件物品有质量和价格两种属性。你要做的是按质量升序排序,若质量相同则按价格降序排序。
Input
多组输入。每组先输入一个正整数n(1<=n && n <= 100),代表有n件物品。接下来的一行有n个正整数Wi(1<= Wi && Wi <= 10000),代表每件物品的质量。再接下来的一行有n个正整数Pi(1 <= Pi && Pi <= 10000),代表每件物品的价格。
Output
对于每组数据输出n行,每行两个数Wi,Pi。顺序为题目描述所要求。
Example Input
31 2 23 2 3
Example Output
1 32 32 2
Hint
#include<iostream>#include<algorithm>using namespace std;typedef struct node{ int price; int quality;}thing;int cmp(thing a, thing b){ if(a.quality==b.quality) return a.price > b.price; return a.quality < b.quality;}int main(){ ios::sync_with_stdio(false); const int maxn = 100000; thing things[maxn]; int n; while(cin>>n) { for(int i=0; i<n; ++i) cin>>things[i].quality; for(int i=0; i<n; ++i) cin>>things[i].price; sort(things, things+n, cmp); for(int i=0; i<n; ++i) cout<<things[i].quality<<" "<<things[i].price<<endl; } return 0;}
0 0
- 老--质价比(直接sort排序)
- 老--质价比
- 老--质价比
- 老--质价比
- 老--质价比
- 老--质价比
- 老--质价比
- 老--质价比
- 老--质价比
- sdut2873老--质价比
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Insertion Sort)
- sdut 2873 老--质价比
- 老--质价比 结构体
- 老--质价比 (sdut oj)
- 排序之直接插入排序(Straight Insertion Sort)
- 使用NGUI项目优化总结
- C# 开源框架
- Java基础_数组
- 获取参数的元数据信息
- 渲染
- 老--质价比(直接sort排序)
- 理解RESTful架构
- Maven基础学习:M2_HOME下文件结构及作用域
- wtsapi32.dll
- form表单写法
- PHP学习笔记——多向条件分支结构switch子句;
- Delete数据如何恢复
- 使用TensorFlow识别照片中的物体
- 1-python图像处理之PIL,pylab