Solving Orde
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.
Input
The first line is an integer which indicates the case number.
And as for each case, the first line is an integer , which is the number of problems.
Then there are lines followed, with a string and an integer in each line, in the -th line, the string means the color of ballon for the -th problem, and the integer means the ballon numbers.
It is guaranteed that:
is about 100.
.
string length .
bolloon numbers .(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 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<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
//#include<bits/stdc++.h>
struct ss{
string color;
int value;
}num[500];//结构体数组:本质是数组,元素是结构体类型,定义了一堆结构体。
bool cmp(ss i, ss j){
return i.value > j.value;
// if(i.value == j.value) {
// return i.color > j.color;
// }else{
// return i.value > j.value;
// }
}
int main(){
int t = 0;
scanf("%d",&t);
while(t--){
int n = 0;
scanf("%d",&n);
for(int i = 0; i < n; i++){
cin >> num[i].color >>num[i].value;
}
sort(num,num + n,cmp);
for(int i = 0; i < n - 1; i++){
cout << num[i].color << " ";
}
cout<< num[n - 1].color ;
cout << endl;
}
return 0;
}
Ignatius and the Princess II
Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5166 says, "I have three question for you, if you can work them out, I will release the Princess, or you will be my dinner, too." Ignatius says confidently, "OK, at last, I will save the Princess."
"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
Input
The input contains several test cases. Each test case consists of two numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume that there is always a sequence satisfied the BEelzebub's demand. The input is terminated by the end of file.
Output
For each test case, you only have to output the sequence satisfied the BEelzebub's demand. When output a sequence, you should print a space between two numbers, but do not output any spaces after the last number.
Sample Input
6 4
11 8
Sample Output
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
//#include<bits/stdc++.h>
//全排列
int main(){
int n = 0,m = 0;
while(scanf("%d %d",&n,&m) != EOF){
int a[2000];
for(int i = 0; i < n; i++){
a[i] = i + 1;
}
int c = 0;
do{
c++;
if(c == m){
for(int i = 0; i < n - 1; i++){
cout << a[i] << " ";
}
cout<< a[n - 1] << endl;
break;
}
}while(next_permutation(a,a + n));
}
return 0;
}
Text Reverse
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
Output
For each test case, you should output the text which is processed.
Sample Input
3
olleh !dlrow
m'I morf .udh
I ekil .mca
Sample Output
hello world!
I'm from hdu.
I like acm.
Hint
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cstdio>
#include<stack>
using namespace std;
//#include<bits/stdc++.h>
//字符翻转
int main(){
int t = 0;
cin >> t;
getchar();
while(t--){
string str;
stack<char> s;
getline(cin,str);
int len = (int)str.length();
for(int i = 0; i < len; i++){
if(str[i] != ' '){
s.push(str[i]);
}
if(str[i] == ' ' || i == len - 1){
while(!s.empty()){
printf("%c",s.top());//先输出一下栈顶元素字母,栈顶元素top,出栈pop
s.pop();//栈顶元素出栈,无需pop(s[i])
}
if(str[i] == ' '){
printf(" ");
}
}
}
// printf("\n");
cout << endl;
}
return 0;
}
ACboy needs your help again!
ACboy was kidnapped!!
he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.
As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy."
The problems of the monster is shown on the wall:
Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out").
and the following N lines, each line is "IN M" or "OUT", (M represent a integer).
and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully!
Input
The input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
Output
For each command "OUT", you should output a integer depend on the word is "FIFO" or "FILO", or a word "None" if you don't have any integer.
Sample Input
4
4 FIFO
IN 1
IN 2
OUT
OUT
4 FILO
IN 1
IN 2
OUT
OUT
5 FIFO
IN 1
IN 2
OUT
OUT
OUT
5 FILO
IN 1
IN 2
OUT
IN 3
OUT
Sample Output
1
2
2
1
1
2
None
2
3
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
//#include<bits/stdc++.h>
//字符翻转
int main(){
int t = 0;
cin >> t;
getchar();
while(t--){
int n = 0;
scanf("%d",&n);
string s1,s2;
cin >> s1;
if(s1 == "FIFO"){
queue<int >q;
while(n--){
cin >> s2;
if(s2 == "IN"){
int num;
cin >> num;
q.push(num);
}else{
if(!q.empty()){
cout << q.front() << endl;
q.pop();
}else{
cout << "None" << endl;
}
}
}
}else{
stack<int >s;
while(n--){
cin >> s2;
if(s2 == "IN"){
int num;
cin >> num;
s.push(num);
}else{
if(!s.empty()){
cout << s.top() << endl;
s.pop();
}else{
cout << "None" << endl;
}
}
}
}
}
return 0;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。