백준 C# BOJ 2884 알람 시계
2020. 1. 9. 21:28ㆍ백준 알고리즘 단계별/if 문
반응형
출제 링크 : https://www.acmicpc.net/problem/2884
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
using System;
using static System.Console;
namespace baekjoon
{
class Program
{
static void Main(string[] args)
{
string inputA = Console.ReadLine();
int h = int.Parse(intputAll[0]); // 시
int m = int.Parse(intputAll[1]); // 분
m = m - 45; // 45분 감소
if (m > 0) // 45분이 감소 해도 그 값이 0 보다 크다면 (10시 46분)
{
WriteLine($"{h} {m}"); // 바로 출력
}
else if (m < 0) // 45분이 감소 해서 그 값이 0 보다 작다면 ( 10시 10분)
{
if (h == 0) // (0시 20분)일때 0시는 전날23시로 바뀌어야 되기때문에
{
h = 23;
}
else // (1시 20분)일때는 전날로 바뀔 필요 없기 때문에
{
h -= 1;
}
m += 60; // 45분이 감소했을때 0보다 작으면 시간이 1 감소하고
// 60분을 올려주기 때문에
WriteLine($"{h} {m}");
}
}
}
}
|
반응형