[SWEA][D1] 2056. 연월일 달력

2025. 5. 27. 19:35·Problem Solving/Algorithm Practice

[SWEA][D1] 2056. 연월일 달력

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);  
        }  
    }  
}
반응형

'Problem Solving > Algorithm Practice' 카테고리의 다른 글

[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
'Problem Solving/Algorithm Practice' 카테고리의 다른 글
  • [SWEA][D1] 2063. 중간값 찾기 Java
  • [SWEA][D1] 2058. 자릿수 더하기 Java
  • [SWEA][D1] 2050. 알파벳을 숫자로 변환 Java
  • [SWEA][D1] 2047. 신문 헤드라인 Java
WHITE_FROST
WHITE_FROST
개발공부리뷰블로그
  • WHITE_FROST
    하얀하얀IT
    WHITE_FROST
  • 전체
    오늘
    어제
    • 분류 전체보기 (138)
      • Infra (5)
      • Project & Troubleshooting (14)
        • Troubleshooting (7)
        • Dev Tools (4)
      • Frontend (30)
        • Next.js (9)
        • React (13)
        • TypeScript (2)
        • JavaScript (6)
      • Mobile (17)
        • React Native (16)
        • Android (1)
      • Backend & Data (7)
        • Database (3)
        • Java (1)
        • Python (2)
        • Design Pattern (1)
      • AI (7)
        • Models & API (1)
        • AI Notes (6)
        • AI Tools (0)
        • Local AI (0)
        • Concepts (0)
      • Problem Solving (52)
        • Algorithm Notes (6)
        • Algorithm Practice (46)
      • Growth Log (9)
        • Study Log (6)
        • Tips (0)
        • Etc (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    ios
    프로그래머스
    react
    오블완
    Next.js
    알고리즘
    리액트네이티브
    boj
    티스토리챌린지
    코테
    d1
    React-Native cli
    백준
    React Hooks
    SWEA
    java
    코딩테스트
    Python
    Claude
    mongodb cloud
    ReactHook
    error
    hooks
    D2
    react-native-maps
    react-native
    javascript
    Ai
    reactnative
    Expo
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
WHITE_FROST
[SWEA][D1] 2056. 연월일 달력
상단으로

티스토리툴바