package file.iostream;
import java.util.*;
/*
都按先录入排列在前的规则处理。
例示:
jack 70
peter 96
Tom 70
smith 67
从高到低 成绩
peter 96
jack 70
Tom 70
smith 67
从低到高
smith 67
Tom 70
jack 70
peter 96
* */
public class Demo2 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
TreeSet<Person1> ts0 = new TreeSet<Person1>(new Comparator<Person1>(){
public int compare(Person1 p1, Person1 p2) {
int num = p2.score - p1.score;
if(num==0)
return p1.name.toLowerCase().compareTo(p2.name.toLowerCase());
else
return num;
}
});//0:从高到低
TreeSet<Person1> ts1 = new TreeSet<Person1>(new Comparator<Person1>(){
public int compare(Person1 p1, Person1 p2) {
int num = p1.score - p2.score;
if(num==0)
return p2.name.toLowerCase().compareTo(p1.name.toLowerCase());
else
return num;
}
});
// 3 0 fang 90 yang 50 ning 70
String[] s = str.split(" ");
for(int i=2;i<s.length-1;i=i+2){
if(s[1].equals("0")){
ts0.add(new Person1(s[i],Integer.parseInt(s[i+1])));
}
if(s[1].equals("1"))
ts1.add(new Person1(s[i],Integer.parseInt(s[i+1])));
}
// String temp = "";
if(s[1].equals("0")){
Iterator<Person1> it = ts0.iterator();
while(it.hasNext()){
Person1 p = it.next();
// temp = temp + p.name+" "+p.score+" ";
sop(p.name+" "+p.score);
}
}
if(s[1].equals("1")){
Iterator<Person1> it = ts1.iterator();
while(it.hasNext()){
Person1 p = it.next();
// temp = temp + p.name+" "+p.score+" ";
sop(p.name+" "+p.score);
}
}
// sop(temp.trim());
}
public static void sop(Object o){
System.out.println(o);
}
}
class Person1{
String name;
int score;
public Person1(String name,int score){
this.name = name;
this.score = score;
}
}
import java.util.*;
/*
* 查找和排序
以人格担保,这道题是题目的问题,到底输入或者输出是多行还是一行,排序时相同成绩的是按姓名的升序还是降序排列,我已经将所有的可能都试了个遍,都是答案错误,好想死一死啊。
都按先录入排列在前的规则处理。
例示:
jack 70
peter 96
Tom 70
smith 67
从高到低 成绩
peter 96
jack 70
Tom 70
smith 67
从低到高
smith 67
Tom 70
jack 70
peter 96
* */
public class Demo2 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
TreeSet<Person1> ts0 = new TreeSet<Person1>(new Comparator<Person1>(){
public int compare(Person1 p1, Person1 p2) {
int num = p2.score - p1.score;
if(num==0)
return p1.name.toLowerCase().compareTo(p2.name.toLowerCase());
else
return num;
}
});//0:从高到低
TreeSet<Person1> ts1 = new TreeSet<Person1>(new Comparator<Person1>(){
public int compare(Person1 p1, Person1 p2) {
int num = p1.score - p2.score;
if(num==0)
return p2.name.toLowerCase().compareTo(p1.name.toLowerCase());
else
return num;
}
});
// 3 0 fang 90 yang 50 ning 70
String[] s = str.split(" ");
for(int i=2;i<s.length-1;i=i+2){
if(s[1].equals("0")){
ts0.add(new Person1(s[i],Integer.parseInt(s[i+1])));
}
if(s[1].equals("1"))
ts1.add(new Person1(s[i],Integer.parseInt(s[i+1])));
}
// String temp = "";
if(s[1].equals("0")){
Iterator<Person1> it = ts0.iterator();
while(it.hasNext()){
Person1 p = it.next();
// temp = temp + p.name+" "+p.score+" ";
sop(p.name+" "+p.score);
}
}
if(s[1].equals("1")){
Iterator<Person1> it = ts1.iterator();
while(it.hasNext()){
Person1 p = it.next();
// temp = temp + p.name+" "+p.score+" ";
sop(p.name+" "+p.score);
}
}
// sop(temp.trim());
}
public static void sop(Object o){
System.out.println(o);
}
}
class Person1{
String name;
int score;
public Person1(String name,int score){
this.name = name;
this.score = score;
}
}