Algorithm

[백준 2884] 알람 시계

Mirab 2021. 11. 29. 21:43
문제 풀이

 

간단한 구현 문제입니다.

h가 0일 때만 24로 계산하고,

m이 45보다 작을 때만 h를 하나 감소하고 m에다가 60을 더해서 계산하면 됩니다.

 

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

	int h, m;
	cin >> h >> m;
	if (m < 45)
	{
		if (h == 0)
		{
			h = 23;
		}
		else
		{
			h--;
		}
		m = 60 + m - 45;
	}
	else
		m -= 45;

	cout << h << ' ' << m << endl;
	return 0;
}

 

 

'Algorithm' 카테고리의 다른 글

[백준 1100] 하얀 칸  (0) 2021.11.30
[백준 1110] 더하기 사이클  (0) 2021.11.29
[백준 1009] 분산처리  (0) 2021.11.27
[백준 16398] 행성 연결  (0) 2021.11.22
[백준 16202] MST 게임  (0) 2021.11.21