您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页hdu 5702 Solving Order

hdu 5702 Solving Order

来源:好走旅游网

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

#include<stdio.h>
#include<string.h>

struct part{
    char color[11];
    int num;
};


int main()
{
    struct part a[100], temp;
    int t, n, i, j;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(i = 0;i < n;i++)
        {
            getchar();
            scanf("%s %d", a[i].color, &a[i].num);
        }

        for(i = 0;i < n;i++)
        {

                for(j = i+1;j < n;j++)
                {
                    if(a[j].num > a[i].num)
                    {
                        temp = a[j];
                        a[j] = a[i];
                        a[i] = temp;
                    }
                }


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

            printf("\n");
    }
    return 0;
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务