Solving Order
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1306 Accepted Submission(s): 859

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.
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.
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
//思路:结构体排序,但是我PE了几次,最后一组数据也要换行!!!
AC源码:
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define LO
struct balloon
{
string col;
int n;
balloon(string a,int b):col(a),n(b){}
bool operator<(const balloon& rhs)
{
return n>rhs.n;
}
};
vector<balloon> bvec;
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
int T;
cin>>T;
while(T--)
{
bvec.clear();
int n;
cin>>n;
string a;
int num;
while(n--)
{
cin>>a>>num;
bvec.push_back(balloon(a,num));
}
sort(bvec.begin(),bvec.end());
int ok=1;
for(int i=0;i<bvec.size();++i)
{
if(ok)
{
cout<<bvec[i].col;
ok=0;
}
else
cout<<' '<<bvec[i].col;
}
cout<<endl;
}
return 0;
}
1227



被折叠的 条评论
为什么被折叠?



