题目描述:
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.
输入描述:
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.
输出描述:
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.
输入:
3
3
red 1
green 2
yellow 3
1
blue 83
2
red 2
white 1
输出:
yellow green red
blue
red white
题意:
作为ACMer,众所周知,每个不同颜色的气球代表一道题,气球数量越多的问题肯定更容易解决。现在,你已经知道每种颜色有多少个气球。请输出你的最优做题顺序顺序,以便从简单到困难地完成问题。按照你解决问题的顺序打印出代表问题的颜色。
题解:
结构体排序
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100 + 5;
struct point{
char s[maxn];
int value;
};
point a[maxn];
int cmp(point x,point y){
return x.value > y.value;
}
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = 0; i < n; i ++){
scanf("%s%d",a[i].s,&a[i].value);
}
sort(a,a + n,cmp);
for(int i = 0; i < n - 1;i ++) printf("%s ",a[i].s);
printf("%s\n",a[n - 1].s);
}
return 0;
}