백준 2884

Hyerin·2021년 11월 29일
0
post-thumbnail

문제

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

C# 풀이

using System;

namespace baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            //입력받고, 각각 분리하고, int형으로 바꾸기
            string strInput = Console.ReadLine(); 
            string[] strNums = strInput.Split(' ');  
            int nHour= int.Parse(strNums[0]);
            int nMin= int.Parse(strNums[1]);

            // 입력한 시간의 45분 전으로 바꾸고, 출력하기
            // 예외
            // 1. nHour == 0 && nMin < 45 
            // 2. nHour != 0 && nMin < 45

            if (nMin < 45)          
            {
                if (nHour == 0)
                {
                    nHour = 23;
                }
                else
                {
                    nHour -= 1;
                }
                nMin += 15;
            }
            else
            { 
                nMin -= 45;
            }

            // void WriteLine(string format, object arg0, object arg1);
            Console.WriteLine("{0} {1}", nHour, nMin);
        }
    }
}

0개의 댓글