zoukankan      html  css  js  c++  java
  • C语言编程练习39:Solving Oder

    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.

    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.
    1n10.
    1 string length 10.
    1 bolloon numbers 83


    InputThe first line is an integer T.(there are 83 teams :p)
    For any two problems, their corresponding colors are different.
    For any two kinds of balloons, their numbers are different.
    OutputFor 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 <iostream>
    #include <cstdio>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    struct ss
    {
        char color[50];
        int pro;
    }ballon[500];
    
    bool cmp(ss x,ss y)
    {
        return x.pro>y.pro;
    }
    int main()
    {
        int T;
        cin >> T;
        while(T--)
        {
            int n;
            cin >> n;
            for(int i=0;i<n;i++)
            {
                cin >> ballon[i].color >>ballon[i].pro;
            }
            sort(ballon,ballon+n,cmp);
            for(int i=0;i<n-1;i++)
            {
                cout << ballon[i].color << ' ';
            }
            cout << ballon[n-1].color << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    JerryScript:物联网开发者的得力工具
    使用 scipy.fft 进行Fourier Transform:Python 信号处理
    解析WeNet云端推理部署代码
    华为云消息队列服务荣获首个双擎可信云稳定性最高级认证
    .NET从互联网上获取当前时间并更新系统时间
    豆瓣电台WP7客户端 开发记录1
    HTML格式化为标准XML
    豆瓣电台WP7客户端 开发记录6
    豆瓣电台 for WP7 客户端开源
    豆瓣电台WP7客户端 开发记录7
  • 原文地址:https://www.cnblogs.com/FantasticDoubleFish/p/14345023.html
Copyright © 2011-2022 走看看