Algorithm/BOJ(Baekjoon Online Judge)
[백준 - 5635번] 생일 - Java //Wello Horld //
koucop
2020. 4. 7. 08:13
이번에는 BOJ의 5635번 문제 "생일" 을 풀어보도록 하자
성공한 코드는 다음과 같다.
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
people[] peoples = new people[n];
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String name = st.nextToken();
String a = st.nextToken();
String b = st.nextToken();
String c = st.nextToken();
if(a.length() == 1) a = "0" + a;
if(b.length() == 1) b = "0" + b;
peoples[i] = new people(name, Integer.parseInt(c + b + a));
}
Arrays.sort(peoples, (a, b) -> b.birthday - a.birthday);
bw.write(peoples[0].name + "\n");
bw.write(peoples[n - 1].name + "\n");
bw.flush();
br.close();
bw.close();
}
static class people {
String name;
int birthday;
public people(String name, int birthday) {
this.name = name;
this.birthday = birthday;
}
}
}
문제 : https://www.acmicpc.net/problem/5635
5635번: 생일
문제 어떤 반에 있는 학생들의 생일이 주어졌을 때, 가장 나이가 적은 사람과 가장 많은 사람을 구하는 프로그램을 작성하시오. 입력 첫째 줄에 반에 있는 학생의 수 n이 주어진다. (1 ≤ n ≤ 100) 다음 n개 줄에는 각 학생의 이름과 생일이 "이름 dd mm yyyy"와 같은 형식으로 주어진다. 이름은 그 학생의 이름이며, 최대 15글자로 이루어져 있다. dd mm yyyy는 생일 일, 월, 연도이다. (1990 ≤ yyyy ≤ 2010, 1 ≤ m
www.acmicpc.net
혹시 코드에 이상한 부분이나 틀린 부분이 있던지, 이해가 안가는 부분이 있다면 댓글로 알려주세요