老--质价比(直接sort排序)



老--质价比

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;

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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西杭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值