sdut 2873 老--质价比

来源:互联网 发布:java高内聚低耦合 编辑:程序博客网 时间:2024/05/01 06:37

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
水题,简单的结构体排序

01#include <iostream>
02#include<string.h>
03#include<stdio.h>
04#include<algorithm>
05using namespace std;
06struct goods
07{
08    int w;
09    int v;
10} p[10000];
11bool cmp(goods a,goods b)
12{
13    if(a.w!=b.w)
14        return a.w<b.w;
15    else
16        return a.v>b.v;
17}
18int main()
19{
20    int n,i;
21    while(cin>>n)
22    {
23        for( i=0; i<n; i++)
24        {
25            cin>>p[i].w;
26        }
27        for(i=0; i<n; i++)
28        {
29            cin>>p[i].v;
30        }
31        sort(p,p+n,cmp);
32        for(i=0; i<n; i++)
33        {
34            printf("%d %d\n",p[i].w,p[i].v);
35        }
36    }
37 
38    return 0;
39}


0 0
原创粉丝点击