import java.util.*;
public class 按身高和体重排队 {
/*
示例 1
输入:
4
100 100 120 130
40 30 60 50
输出:
2134
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//人数
int count = sc.nextInt();
ArrayList<Person> arrayList = new ArrayList<>();
//先存身高
for (int i = 1; i < count + 1; i++) {
Person p = new Person(i);
int height = sc.nextInt();
p.setHeight(height);
arrayList.add(p);
}
//存体重
arrayList.forEach(p->{
int weight = sc.nextInt();
p.setWeight(weight);
});
//直接使用stream的特性,连续排序两次。
List<Person> collect = arrayList.stream()
.sorted(Comparator.comparing(Person::getHeight)
.thenComparing(Person::getWeight))
.toList();
collect.forEach(
p -> System.out.print(p.getId())
);
System.out.println();
}
}
class Person{
int id;
int height;
int weight;
public Person(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
}
按身高和体重排队(华为OD,Java)
最新推荐文章于 2024-05-01 13:29:01 发布