반응형
import java.util.Scanner;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
sc.nextLine();
for(int test_case = 1; test_case <= T; test_case++)
{
String InputDays;
String result;
InputDays = sc.nextLine();
if (InputDays.length() != 8){
System.out.println("#"+test_case + " -1");
continue;
}
String StringYear = InputDays.substring(0,4);
String StringMonth = InputDays.substring(4,6);
String StringDay = InputDays.substring(6,8);
int Year = Integer.parseInt(StringYear);
int Month = Integer.parseInt(StringMonth);
int Day = Integer.parseInt(StringDay);
if( Month < 1 || Month > 12 ){
System.out.println("#"+test_case + " -1");
continue;
}
int[] maxDays = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if(Day < 1 || Day > maxDays[Month]){
System.out.println("#"+test_case + " -1");
continue;
}
System.out.println("#"+test_case + " "+ StringYear + "/"+ StringMonth+ "/" +StringDay);
}
}
}
반응형
'알고리즘' 카테고리의 다른 글
[SWEA][D1] 2063. 중간값 찾기 Java (0) | 2025.05.27 |
---|---|
[SWEA][D1] 2058. 자릿수 더하기 Java (0) | 2025.05.27 |
[SWEA][D1] 2050. 알파벳을 숫자로 변환 Java (0) | 2025.05.27 |
[SWEA][D1] 2047. 신문 헤드라인 Java (0) | 2025.05.27 |
[SWEA][D1] 2046. 스탬프 찍기 Java (0) | 2025.05.27 |