알고리즘/기타
[swea] 1948. 날짜 계산기(Java 풀이)
파프리카.
2023. 8. 20. 22:56
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PnnU6AOsDFAUq
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com

import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 월별 마지막 날짜
// 월을 인덱스와 맞췄다
int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
// 테스트케이스 입력
int T = sc.nextInt();
for (int tc = 1; tc <= T; tc++) {
int ans = 0;
// 첫 번째 날짜
int month_1st = sc.nextInt();
int day_1st = sc.nextInt();
// 두 번째 날짜
int month_2nd = sc.nextInt();
int day_2nd = sc.nextInt();
// 계산하자
while(month_1st<month_2nd) {
ans+=days[month_1st++];
}
ans=ans-day_1st+day_2nd+1;
System.out.printf("#%d %d\n", tc, ans);
}
}
}
+(사담)고민을 해봤는데 결론부터 말하자면 이제부터 자바쟁이가 되려고 한다. 벌려놓은 일이 있어 파이썬은 버리지는 않을건데 자바 비중을 더 늘일 예정이다.