Algorithm/BOJ
백준 1308번 C++
poopooreum
2023. 7. 23. 09:20
반응형
백준 1308번 D-day
https://www.acmicpc.net/problem/1308
1308번: D-Day
첫째 줄에 오늘의 날짜가 주어지고, 두 번째 줄에 D-Day인 날의 날짜가 주어진다. 날짜는 연도, 월, 일순으로 주어지며, 공백으로 구분한다. 입력 범위는 1년 1월 1일부터 9999년 12월 31일 까지 이다.
www.acmicpc.net


정답 코드
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
int arr[] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
};
int cal(int y, int M) {
int r = 0;
for (int i = 1; i <= y; ++i) {
for (int j = 0; j < (i == y ? M - 1 : 12); ++j) {
r += arr[j];
if (j == 1 && ((i % 400 == 0) || (i % 4 == 0 && i % 100 != 0))) {
++r;
}
}
}
return r;
}
int main() {
fastio;
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int ans = cal(d, e) + f - cal(a, b) - c;
cout << (ans > cal(1001, 1) ? "gg" : "D-" + to_string(ans));
return 0;
}
문제 풀이
브루트포스 알고리즘에 관한 문제입니다.
반응형