알고리즘
백준 1476 날짜 계산
중국고대사
2019. 3. 26. 15:17
15 * 28 * 18 = 7980이기 때문에 시간 제한안에 모든 경우의 수를 다 해볼 수 있다.
각각 최대치를 넘어갈 때 1로 초기화시켜주고, 주어진 날과 일치할 때 멈춘 후 year를 출력한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> using namespace std; int main(int argc, char* argv[]) { int e, s, m, E, S, M; long long year; e = s = m = year = 1; cin >> E >> S >> M; while(true){ if (e == E && s == S && m == M) { cout << year << '\n'; break; } e++, s++, m++, year++; if (e == 16)e = 1; if (s == 29)s = 1; if (m == 20)m = 1; } return 0; } | cs |
출처: https://www.acmicpc.net/problem/1476