※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 4327번 문제인 Combination Lock이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/4327 

 

4327번: Combination Lock

Now that you're back to school for another term, you need to remember how to work the combination lock on your locker. A common design is that of the Master Brand, shown at right. The lock has a dial with 40 calibration marks numbered 0 to 39. A combinatio

www.acmicpc.net

주어진 combination lock을 문제에서 지시하는 대로 돌려 문제를 해결하자.

 

combination lock을 시계방향으로 돌리면 눈금의 값이 점점 감소하고 반시계방향으로 돌리면 눈금의 값이 증가함에 유의해 구현해주자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int a, b, c, d;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> a >> b >> c >> d;

	while (a + b + c + d) {
		int unit = 0;
		if (a >= b) unit += a - b;
		else unit += (a + 40) - b;
		if (b <= c) unit += c - b;
		else unit += (c + 40) - b;
		if (c >= d) unit += c - d;
		else unit += (c + 40) - d;

		cout << unit * 9 + 1080 << '\n';
		cin >> a >> b >> c >> d;
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 5343 // C++] Parity Bit  (0) 2022.12.22
[BOJ 6830 // C++] It's Cold Here!  (0) 2022.12.22
[BOJ 26587 // C++] Reverse  (0) 2022.12.22
[BOJ 5340 // C++] Secret Location  (0) 2022.12.22
[BOJ 5342 // C++] Billing  (0) 2022.12.22

+ Recent posts