※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 6888번 문제인 Terms of Office이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/6888
6888번: Terms of Office
In CS City, a mathematical place to live, the mayor is elected every 4 years, the treasurer is appointed every 2 years, the chief programmer is elected every 3 years and the dog-catcher is replaced every 5 years. This year, Year $X$, the newly elected mayo
www.acmicpc.net
모든 투표가 전부 열리는 간격은 2, 3, 4, 5의 최소공배수와 같은 60년 간격임을 관찰하자.
이를 이용해, 지금 년도부터 주어진 미래의 년도까지 60년 주기로 각 년도를 출력해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int L, R;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> L >> R;
while (L <= R) {
cout << "All positions change in year " << L << '\n';
L += 60;
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26577 // C++] Math (0) | 2022.12.20 |
---|---|
[BOJ 26576 // C++] Date (0) | 2022.12.20 |
[BOJ 2380 // Befunge] Star (0) | 2022.12.20 |
[BOJ 6916 // C++] 0123456789 (0) | 2022.12.20 |
[BOJ 26578 // C++] Word (0) | 2022.12.20 |