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

 

이번에 볼 문제는 백준 9698번 문제인 SAHUR & IMSA’이다.
문제는 아래 링크를 확인하자.

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

 

9698번: SAHUR & IMSA’

Midhat is a Network Security Engineer, based in Sarajevo. He is assigned to do some important consultation projects around the globe in July and August 2013. It happened that Ramadhan (the fasting month for Muslim) falls during these months for the year 20

www.acmicpc.net

주어진 시각에서 45분 전 시각을 표기하는 문제이다.

 

시각/시간의 뺄셈을 초등학교 교과서에 나오듯이 계산하는 코드를 작성해 문제를 해결하자.

 

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

#include <iostream>
using namespace std;

int T;
int H, M;

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

	cin >> T;
	for (int t = 1; t <= T; t++) {
		cin >> H >> M;
		M -= 45;
		if (M < 0) M += 60, H--;
		if (H < 0) H += 24;
		cout << "Case #" << t << ": " << H << ' ' << M << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 8794 // C++] Poniedziałki  (0) 2023.01.06
[BOJ 24603 // C++] Scaling Recipe  (0) 2023.01.06
[BOJ 24311 // C++] ПЪТУВАНЕ  (0) 2023.01.06
[BOJ 5157 // C++] Bailout Bonus  (0) 2023.01.06
[BOJ 25495 // C++] 에어팟  (0) 2023.01.05

+ Recent posts