CodeUp - 1805 : 입체기동장치 생산공장
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<Storage> storages = new ArrayList<>();
for (int i = 0; i < count; i++) {
int id = scanner.nextInt();
int gas = scanner.nextInt();
storages.add(new Storage(id, gas));
}
scanner.close();
storages = storages.stream()
.sorted((e2, e1) -> e2.getId() - e1.getId())
.collect(Collectors.toList());
for (Storage storage : storages) {
System.out.printf("%d %d\n", storage.getId(), storage.getGas());
}
}
}
class Storage {
int id;
int gas;
public int getId() {
return id;
}
public int getGas() {
return gas;
}
Storage(int id, int gas) {
this.id = id;
this.gas = gas;
}
}
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
Map<Integer, Integer> storages = new HashMap<>();
for (int i = 0; i < count; i++) {
int id = scanner.nextInt();
int gas = scanner.nextInt();
storages.put(id, gas);
}
List<Integer> storagesKeys = new ArrayList<>(storages.keySet());
for (int storagesKey : storagesKeys) {
System.out.printf("%d %d\n", storagesKey, storages.get(storagesKey));
}
}
}