标签:顺序 pretty data span each OWIN 就是 res 输出
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
标签:顺序 pretty data span each OWIN 就是 res 输出
原文地址:https://www.cnblogs.com/yaopengcaiji/p/8886242.html