프로그래밍 문제

[백준][C#] 2884번, 알람 시계

sorry0101 2023. 10. 12. 11:19

문제

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

 

2884번: 알람 시계

상근이는 매일 아침 알람을 듣고 일어난다. 알람을 듣고 바로 일어나면 다행이겠지만, 항상 조금만 더 자려는 마음 때문에 매일 학교를 지각하고 있다. 상근이는 모든 방법을 동원해보았지만,

www.acmicpc.net

반례

입력 0 45

출력 0 0

풀이

더보기
using System;

namespace AlgorithmTest
{
    class cSharpPractice
    {
        static void Main()
        {
            string[] time = Console.ReadLine().Split(" ");
            int h = Int32.Parse(time[0]);
            int m = Int32.Parse(time[1]);

            int total_m = (h == 0) ? (24 * 60 + m) : (h * 60 + m);
            int early_time = total_m - 45;

            int early_h = early_time / 60;
            int early_m = early_time % 60;

            early_h = (early_h == 24) ? 0 : early_h;
            Console.WriteLine($"{early_h} {early_m}");
        }
    }
}

Comment

왜 틀렸나 처음엔 몰랐는데 반례를 생각 못했다.

문제에서 범위를 잘 확인하자.


참고

https://www.acmicpc.net/board/view/100873

'프로그래밍 문제' 카테고리의 다른 글

[백준][C#] 1072번, 게임  (0) 2024.09.12
[백준][C#] 1260번, DFS와 BFS  (0) 2024.09.10
[백준][C#] 15552번, 빠른 A+B  (0) 2023.10.12
[백준][C#] 2480번, 주사위 세개  (0) 2023.10.12
[백준][C#] 2525번, 오븐 시계  (1) 2023.10.12