老--质价比
Time Limit: 1000MS
Memory Limit: 65536KB
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
3 1 2 2 3 2 3
Example Output
1 3 2 3 2 2
Hint
#include<iostream>
#include<algorithm>
using namespace std;
struct st
{
int w,p;
}a[100];
int cmp(st a,st b)
{
if(a.w!=b.w)
return a.w<b.w;
return a.p>b.p;
}
int main()
{
int n;
while(cin>>n)
{
int w[100],p[100];
for(int i=0;i<n;i++)
{
cin>>w[i];
}
for(int i=0;i<n;i++)
{
cin>>p[i];
}
for(int i=0;i<n;i++)
{
a[i].w=w[i];
a[i].p=p[i];
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++)
cout<<a[i].w<<" "<<a[i].p<<endl;
}
return 0;
}
/***************************************************
User name: zxw140231刘真真
Result: Accepted
Take time: 0ms
Take Memory: 152KB
Submit time: 2017-01-11 11:02:54
****************************************************/
574

被折叠的 条评论
为什么被折叠?



