## 题目描述

N只小白鼠(1 <= N <= 100)，每只鼠头上戴着一顶有颜色的帽子。

## 样例输入

``````3
30 red
50 blue
40 green
``````

## 样例输出

``````blue
green
red
``````

## 代码实现

``````import java.util.Random;
import java.util.Scanner;

public class Main {
public static int Random_Partition(int a[],String s[],int p,int q) {
//随机选取基准
Random random = new Random();
int i = random.nextInt(q)%(q-p+1) + p;
swap(a,s,q,i);
return partition(a, s, p, q);
}

public static void swap(int a[],String s[],int i,int j) {
//交换函数
int t;
t = a[i];
a[i] = a[j];
a[j] = t;

String temp;
temp = s[i];
s[i] = s[j];
s[j] = temp;
}

public static int partition(int a[],String s[],int p,int q) {
//分区函数，数据分区
int x=a[p];
int i=p;
for(int j=p+1;j<=q;j++) {
if(a[j]<=x) {
i = i+1;
swap(a,s,i,j);
}
}
swap(a,s,p,i);
return i;
}

public static void QuickSort(int a[],String s[],int p,int q) {
//排序函数，递归排序
if(p<q) {
int r = Random_Partition(a, s, p, q);
//基准随机产生
QuickSort(a,s, p, r-1);
QuickSort(a,s, r+1, q);
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
while(sc.hasNext()) {
n = sc.nextInt();
int a[] = new int[n];
String s[] = new String[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
s[i] = sc.next();
}
QuickSort(a, s, 0, n-1);
for(int i=n-1;i>=0;i--) {
System.out.println(s[i]);
}
}
}
}
``````