HDU5702 Solving Order【排序】

Solving Order

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3343 Accepted Submission(s): 2032

Problem Description
Welcome to HDU to take part in the first CCPC girls' competition!
在这里插入图片描述

As a pretty special competition, many volunteers are preparing for it with high enthusiasm.
One thing they need to do is blowing the balloons.

Before sitting down and starting the competition, you have just passed by the room where the boys are blowing the balloons. And you have found that the number of balloons of different colors are strictly different.

After thinking about the volunteer boys' sincere facial expressions, you noticed that, the problem with more balloon numbers are sure to be easier to solve.

Now, you have recalled how many balloons are there of each color.
Please output the solving order you need to choose in order to finish the problems from easy to hard.
You should print the colors to represent the problems.

Input
The first line is an integer T which indicates the case number.
And as for each case, the first line is an integer n, which is the number of problems.
Then there are n lines followed, with a string and an integer in each line, in the i-th line, the string means the color of ballon for the i-th problem, and the integer means the ballon numbers.

It is guaranteed that:
T is about 100.
1≤n≤10.
1≤ string length ≤10.
1≤ bolloon numbers ≤83.(there are 83 teams :p)
For any two problems, their corresponding colors are different.
For any two kinds of balloons, their numbers are different.

Output
For each case, you need to output a single line.
There should be n strings in the line representing the solving order you choose.
Please make sure that there is only a blank between every two strings, and there is no extra blank.

Sample Input
3
3
red 1
green 2
yellow 3
1
blue 83
2
red 2
white 1

Sample Output
yellow green red
blue
red white

Source
"巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场

问题链接HDU5702 Solving Order
问题简述
    给出多种颜色的名称与分值,按分值递减顺序输出颜色名称。
问题分析
    这是一个简单的排序问题,构建一个结构体排一下序再输出就可以了。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* HDU5702 Solving Order */

#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

const int N = 10;
struct Node {
    char color[N + 1];
    int val;
} a[N];

bool cmp(Node a, Node b)
{
    return a.val > b.val;
}

int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
            scanf("%s%d", a[i].color, &a[i].val);

        sort(a, a + n, cmp);

        printf("%s", a[0].color);
        for(int i = 1; i < n; i++)
            printf(" %s", a[i].color);
        printf("\n");
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10205971.html