3004 : 데이터 재정렬
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
List<Data> dataList = new ArrayList<>();
for (int i = 0; i < count; i++) {
int value = scanner.nextInt();
dataList.add(new Data(0, value));
}
List<Data> dataStreamList = dataList.stream()
.sorted((e2, e1) -> e2.getValue() - e1.getValue())
.collect(Collectors.toList());
for (int i = 0; i < dataStreamList.size(); i++) {
dataStreamList.get(i).setId(i);
}
String result = dataList
.stream()
.map(e -> e.getId() + "")
.collect(Collectors.joining(" "));
System.out.println(result);
}
}
class Data {
int id;
int value;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getValue() {
return value;
}
@Override
public String toString() {
return "Data{" +
"id = " + id +
", value = " + value +
'}';
}
Data(int id, int value) {
this.id = id;
this.value = value;
}
}