본문 바로가기
Java/SW Expert Academy

1948. 날짜 계산기

by GLOWWW 2021. 1. 11.
package oSWExpertAcademy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class D2_1948 {
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int testCase = Integer.parseInt(br.readLine());
            for(int tc=1; tc<=testCase; tc++) {
                //각 월마다 날짜 배열 생성 
                int[] dayCount = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
                StringTokenizer st = new StringTokenizer(br.readLine());
                //첫번째 월 
                int aMonth = Integer.parseInt(st.nextToken());
                //첫번째 일 
                int aday = Integer.parseInt(st.nextToken());
                //두번째 월 
                int bMonth = Integer.parseInt(st.nextToken());
                //두번째 일 
                int bday = Integer.parseInt(st.nextToken());
                //입력 확인 
                //System.out.println(aMonth+" "+aday+" "+bMonth+" "+bday);
                //일수 구하기 
                int sum = bday - aday + 1;
                for(int i=aMonth; i<bMonth; i++) {
                    sum += dayCount[i-1];
                }
                System.out.println("#"+tc+" "+sum);

            }//testCase for문 
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

'Java > SW Expert Academy' 카테고리의 다른 글

1945. 간단한 소인수분해  (0) 2021.01.11
1946. 간단한 압축 풀기  (0) 2021.01.11
1954. 달팽이 숫자  (0) 2021.01.11
1959. 두 개의 숫자열  (0) 2021.01.09
1961. 숫자 배열 회전  (0) 2021.01.09

댓글