알고리즘/자료구조
[코드업] 스케줄 정리 (구조체 연습) - Java
jny0
2023. 3. 2. 20:47
https://codeup.kr/problem.php?id=3019
스케줄 정리
5 sleep 2014 05 23 golf 2014 06 02 travel 2015 11 22 baseball 2013 02 01 study 2014 05 23
codeup.kr
스트림 - 정렬
stream().sorted()
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
//int n = sc.nextInt();
List<schedule> list = new ArrayList<>();
for(int i=0; i<n; i++){
String[] param = sc.nextLine().split(" ");
String name = param[0];
int year = Integer.parseInt(param[1]);
int month = Integer.parseInt(param[2]);
int day = Integer.parseInt(param[3]);
list.add(new schedule(name, year, month, day));
}
list.stream().sorted(Comparator.comparing(schedule::getYear)
.thenComparing(schedule::getMonth)
.thenComparing(schedule::getDay)
.thenComparing(schedule::getName))
.map(schedule::getName)
.forEach(System.out::println);
}
}
class schedule{
private String name;
private int year;
private int month;
private int day;
public schedule(String name, int year, int month, int day) {
this.name = name;
this.year = year;
this.month = month;
this.day = day;
}
public String getName() {
return name;
}
public int getYear() {
return year;
}
public int getMonth() {
return month;
}
public int getDay() {
return day;
}
}