Solving Order
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 352 Accepted Submission(s): 238
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.
![](https://i-blog.csdnimg.cn/blog_migrate/447d60ff4d002c0b038af203168398a7.jpeg)
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 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.
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.
Output
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.
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.
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
简单题,但想用这题来写set练一练。定义了一个颜色的结构体,包含它的名字以及气球个数,在结构体中重载了 < 的操作为了后续读入set中。并且重载了<<的操作用来后面cout
下面是代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
struct unit{
string name;
int num;
bool operator < (const unit &b) const{
return num>b.num;
}
};
ostream& operator << (ostream &out,const unit &p){
out<<p.name;
return out;
}
int main(){
int t,n,i,k;
scanf("%d",&t);
set<unit> git;
unit middle;
while(t--){
git.clear();
scanf("%d",&n);
k=0;
for(i=0;i<n;i++){
cin>>middle.name>>middle.num;
git.insert(middle);
}
i=0;
for(set<unit>::iterator it=git.begin();it!=git.end();it++){
cout<<*it;
if(i<n-1){
printf(" ");
}
i++;
}
printf("\n");
}
return 0;
}
还有一个问题。。。。这个程序对<<重载是在结构体外部,那么如何在结构题内部重载<<呢??