这个题让我有了以前没有的动力
Posted yaopengcaiji
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了这个题让我有了以前没有的动力相关的知识,希望对你有一定的参考价值。
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.
1≤n≤101≤n≤10.
1≤1≤ string length ≤10≤10.
1≤1≤ 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; }
好了,这是我的第一次写,可能看的一脸蒙T_T
以上是关于这个题让我有了以前没有的动力的主要内容,如果未能解决你的问题,请参考以下文章