반응형
풀이 언어 : JAVA
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
/*
표준입력 System.in 으로부터 스캐너를 만들어 데이터를 읽어옵니다.
*/
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
/*
여러 개의 테스트 케이스가 주어지므로, 각각을 처리합니다.
*/
for(int test_case = 1; test_case <= T; test_case++)
{
String input = sc.next();
if (input.length() != 8) {
System.out.println("#" + test_case + " " + "-1");
continue;
}
String year_s = input.substring(0,4);
String month_s = input.substring(4,6);
String day_s = input.substring(6,8);
int month = Integer.parseInt(month_s);
int day = Integer.parseInt(day_s);
if (month > 12 || month < 1) {
System.out.println("#" + test_case + " " + "-1");
continue;
}
if (month == 2) {
if (day > 28) {
System.out.println("#" + test_case + " " + "-1");
continue;
}
} else if (month == 1 || month == 3 || month == 5 || month == 7 || month ==8 || month == 10 || month ==12) {
if (day > 31) {
System.out.println("#" + test_case + " " + "-1");
continue;
}
} else {
if (day > 30) {
System.out.println("#" + test_case + " " + "-1");
continue;
}
}
System.out.println("#" + test_case + " " + year_s + "/" + month_s + "/" + day_s);
}
return;
}
}
링크
반응형
'알고리즘 > 과제' 카테고리의 다른 글
백준 1181번 단어 정렬 (0) | 2021.09.05 |
---|---|
SW Expert Academy 4613. 러시아 국기 같은 깃발 (0) | 2021.08.27 |
SW Expert Academy 2068. 최대수 구하기 (0) | 2021.08.21 |
댓글