๐ฌ Java ๋ฌธ๋ฒ์ ๋ง์ด ๊ธฐ์ตํ์ง ๋ชปํด์ ์์ฌ์ ์ต๋๋ค. Map, List์ ๋ํด ๊ณต๋ถํ๋ ์๊ฐ์ด ํ์ํจ์ ๋๊ผ์ต๋๋ค.
์ด๋ค ๋ฐ์ ์๋ ํ์๋ค์ ์์ผ์ด ์ฃผ์ด์ก์ ๋, ๊ฐ์ฅ ๋์ด๊ฐ ์ ์ ์ฌ๋๊ณผ ๊ฐ์ฅ ๋ง์ ์ฌ๋์ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ด๋ฆ์ด ๊ฐ๊ฑฐ๋, ์์ผ์ด ๊ฐ์ ์ฌ๋์ ์๋ค.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException, ParseException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
String day;
String month;
String year;
HashMap<Date, String> answer = new HashMap<>();
Date tmp[] = new Date[T];
// save input values
for(int t = 0; t < T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String name = st.nextToken();
day = st.nextToken();
month = st.nextToken();
year = st.nextToken();
String date = year + '-' + month + '-' + day;
// String to Date
SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd");
Date result = transFormat.parse(date);
answer.put(result, name);
tmp[t] = result;
}
Arrays.sort(tmp);
// Print Answer
System.out.println(answer.get(tmp[T-1]));
System.out.println(answer.get(tmp[0]));
}
}
์์ผ๋ก ํ์ดํ ์ ๋๋ค ๐ฆพ