码迷,mamicode.com
首页 > 其他好文 > 详细

这个题让我有了以前没有的动力

时间:2018-04-19 21:46:50      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:顺序   pretty   data   span   each   OWIN   就是   res   输出   

G-Solving Order
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. 

InputThe first line is an integer TT which indicates the case number. 
And as for each case, the first line is an integer nn, which is the number of problems. 
Then there are nn lines followed, with a string and an integer in each line, in the ii-th line, the string means the color of ballon for the ii-th problem, and the integer means the ballon numbers. 

It is guaranteed that: 
TT is about 100. 
1n101≤n≤10. 
11≤ string length 10≤10. 
11≤ bolloon numbers 83≤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. 
OutputFor each case, you need to output a single line. 
There should be nn 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>
#include<algorithm>
using namespace std;
struct lianjie
{
    char color[11];
    int num;
};
int cmp(struct lianjie q,struct lianjie w)///定义了两个结构体变量q,w,返回num较大的;
{
    return q.num>w.num;
}
int main()///看题要从main函数先看
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        struct lianjie e[101];
        int n,i;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            scanf("%s %d",e[i].color,&e[i].num);///存每一组的气球颜色和数量;
        }
        sort(e,e+n,cmp);///给结构体排序,降序;我之前没想到sort能这样用
        for(i=0; i<n; i++)
        {
            if(i==0)
            {
                printf("%s",e[i].color);
            }
            else printf(" %s",e[i].color);
        }
        printf("\n");
    }
    return 0;
}
View Code

好了,这是我的第一次写,可能看的一脸蒙T_T

这个题让我有了以前没有的动力

标签:顺序   pretty   data   span   each   OWIN   就是   res   输出   

原文地址:https://www.cnblogs.com/yaopengcaiji/p/8886242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!