HyeLog
1476_날짜 계산 본문
나머지를 이용해서 풀었다.
처음에 경계값에 대한 예외처리를 하지 않아서 틀렸던 문제다.
(year % 15)의 범위는 0 ~ 14 이기 때문에, (year % 15 == e) 와 같이 쓰면, e가 15인 경우는 처리할 수 없게 된다.
따라서, ((year - 1) % 15 + 1 == e) 로 예외 처리를 해줘서 해결했다.
⭕맞는 코드⭕
#include <iostream>
#define E 15
#define S 28
#define M 19
using namespace std;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int e, s, m;
cin >> e >> s >> m;
int year = 1;
while (1) {
if (((year - 1) % E + 1 == e) && ((year - 1) % S + 1 == s) && ((year - 1) % M + 1 == m)) {
cout << year << '\n';
break;
}
year++;
}
return 0;
}
'알고리즘' 카테고리의 다른 글
1107_리모컨 (0) | 2023.01.04 |
---|---|
2309_일곱 난쟁이 (0) | 2022.12.23 |
3085_사탕게임 (0) | 2022.12.23 |
1978_소수 찾기 (0) | 2022.12.08 |
백준_11060_점프 점프 (0) | 2022.08.02 |