코딩 테스트/SW Expert Academy
[SWEA/Java] 2056. 연월일 달력(D1)
에반셀린
2023. 4. 9. 13:55
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
문제 설명
풀이 코드(Java)
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 1; i <= t; i++) {
String s = sc.next();
int month = Integer.valueOf(s.substring(4, 6));
int day = Integer.valueOf(s.substring(6, 8));
String res = "-1";
if (1 <= month && month <= 12 && 1 <= day && day <= daysOfMonth[month - 1]) {
res = String.format("%s/%s/%s", s.substring(0,4), s.substring(4,6), s.substring(6,8));
}
System.out.format("#%d %s\n", i, res);
}
}
}