๐Ÿ‘ฉโ€๐Ÿ’ป BOJ_5635_์ƒ์ผ

YOU KNOW I MEANยท2021๋…„ 11์›” 2์ผ
0
post-thumbnail

๐Ÿ’ฌ Java ๋ฌธ๋ฒ•์„ ๋งŽ์ด ๊ธฐ์–ตํ•˜์ง€ ๋ชปํ•ด์„œ ์•„์‰ฌ์› ์Šต๋‹ˆ๋‹ค. Map, List์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•˜๋Š” ์‹œ๊ฐ„์ด ํ•„์š”ํ•จ์„ ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค.


๐Ÿ“„ ๋ฌธ์ œ

์–ด๋–ค ๋ฐ˜์— ์žˆ๋Š” ํ•™์ƒ๋“ค์˜ ์ƒ์ผ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋‚˜์ด๊ฐ€ ์ ์€ ์‚ฌ๋žŒ๊ณผ ๊ฐ€์žฅ ๋งŽ์€ ์‚ฌ๋žŒ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.
์ด๋ฆ„์ด ๊ฐ™๊ฑฐ๋‚˜, ์ƒ์ผ์ด ๊ฐ™์€ ์‚ฌ๋žŒ์€ ์—†๋‹ค.


๐Ÿ’ก ํ’€์ด ๋ฐฉ๋ฒ•

  • ๋…„, ์›”, ์ผ์„ String์œผ๋กœ ๋ฐ›์•„์™€ Date๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ณ€ํ™˜๋œ ๋‚ ์งœ๋ฅผ Key๋กœ ์ด๋ฆ„์„ Value๋กœ ์„ค์ •ํ•˜์—ฌ HashMap์— ๋„ฃ์Šต๋‹ˆ๋‹ค.
  • ๋ณ€ํ™˜๋œ ๊ฐ’์„ ์ž„์‹œ ๋ฐฐ์—ด์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
    - ์ž„์‹œ ๋ฐฐ์—ด์„ ๋‚˜์ด ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค.
    • ์ •๋ ฌ๋œ ๊ฐ’์„ ํ†ตํ•ด ์ด๋ฆ„์„ ์ฐพ์•„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ”ฅ ์ฝ”๋“œ

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]));
	}

}

2๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2021๋…„ 11์›” 2์ผ

์•ž์œผ๋กœ ํ™”์ดํŒ…์ž…๋‹ˆ๋‹ค ๐Ÿฆพ

1๊ฐœ์˜ ๋‹ต๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด