输入输出样例
输入 #1
5
HIGHHOPES
UP
LOWFEELINGS
UP
UPANDDOWN
DOWN
IAMSTILLSTANDING
DOWN
FOOLINGAROUND
DOWN
输出 #1
UPANDDOWN
IAMSTILLSTANDING
FOOLINGAROUND
HIGHHOPES
LOWFEELINGS
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static class off{
private String a; //名字
private String b; //状态
public off(){
}
public off(String a,String b){
this.a=a;
this.b=b;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String r=sc.nextLine();
off x[]=new off[n];
int w[]=new int[n]; //装上升状态的
int s[]=new int[n]; //装下降的
int e[]=new int[n]; //装不变的
int q=0,p=0,o=0;
for (int i = 0; i < x.length; i++) { //存数据
String A=sc.next();
String B=sc.next();
x[i]=new off(A,B);
if(B.equals("UP")){
w[q++]=i;
}else if(B.equals("DOWN")){
s[p++]=i;
}else{
e[o++]=i;
}
}
ArrayList<String> d=new ArrayList<String>();
for (int i = 0; i <p; i++) { //先放下降的
d.add(x[s[i]].a);
}
for (int i = 0; i <q; i++) { // 再放上升的
d.add(x[w[i]].a);
}
for (int i = 0; i <o; i++) { // 最后插一插
d.add((e[i]),x[e[i]].a);
}
for (int i = 0; i < d.size(); i++) {
System.out.println(d.get(i));
}
}
}