hdu 5702 Solving Order(结构体排序 水题)
Posted qiqi_starsky
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 5702 Solving Order(结构体排序 水题)相关的知识,希望对你有一定的参考价值。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5702
Solving Order
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 184 Accepted Submission(s): 135
Problem Description
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.
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.
Input
The first line is an integer T which
indicates the case number.
And as for each case, the first line is an integern ,
which is the number of problems.
Then there aren 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.
And as for each case, the first line is an integer
Then there are
It is guaranteed that:
For any two problems, their corresponding colors are different.
For any two kinds of balloons, their numbers are different.
Output
For each case, you need to output a single line.
There should ben 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.
There should be
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
Source
解题思路:将变量存在结构体中,然后结构体排序即可。还需要注意格式的问题。
详见代码。
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct node { char ch[110]; int num; }s[110]; bool cmp(node a,node b) { return a.num>b.num; } int main() { int t; scanf("%d",&t); while (t--) { int n; scanf("%d",&n); for (int i=0;i<n;i++) { scanf("%s%d",s[i].ch,&s[i].num); } sort(s,s+n,cmp); for (int i=0;i<n;i++) { printf("%s%c",s[i].ch,i!=n-1?' ':'\n'); } } return 0; }
以上是关于hdu 5702 Solving Order(结构体排序 水题)的主要内容,如果未能解决你的问题,请参考以下文章
Conda安装软件报错:Solving environment: failed with initial frozen solve. UnsatisfiableError: