[BAEKJOON] 백준 10372: Alarm Clock (C#)

2024. 6. 5. 17:39IT/BaekJoon

문제 링크

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

 

 

문제

Alice likes her digital alarm clock. She sets them up every evening. Last night Alice had a dream about her clock. Unfortunately, the only thing she is able to remember is the number of highlighted segments of the clock. Alice wonders what time was set on the clock in her dream.

Alice’s clock have four digits: two for hours and two for minutes. For example, the clock below shows 9:30 (note the leading zero).

The clock uses following digit representation.

 

 

입력

The only line of the input file contains single integer n — the number of highlighted segments of the clock in Alice’s dream (0 ≤ n ≤ 30).

 

 

출력

Output five characters in “hh:mm” format — the time shown on the clock in Alice’s dream. The time must be correct: 0 ≤ hh < 24 and 0 ≤ mm < 60. If there are many possible correct times, output any of them. If there is none, output “Impossible”.

 

 

 

통과한 답안

namespace _10372
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int segments = int.Parse(Console.ReadLine());

            int[] segmentCnt = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

            for (int hh = 0; hh < 24; hh++)
            {
                for (int mm = 0; mm < 60; mm++)
                {
                    int totalSegments = 0;

                    totalSegments += segmentCnt[hh / 10];
                    totalSegments += segmentCnt[hh % 10];
                    totalSegments += segmentCnt[mm / 10];
                    totalSegments += segmentCnt[mm % 10];

                    if (totalSegments == segments)
                    {
                        Console.WriteLine($"{hh:D2}:{mm:D2}");
                        return;
                    }
                }
            }

            Console.WriteLine("Impossible");
        }

        // 0 - 6, 1 - 2, 2 - 5, 3 - 5, 4 - 4,
        // 5 - 5, 6 - 6, 7 - 3, 8 - 7, 9 - 6
        // 최소 22:22(8), 최대 08:08(26)
        // 1번 자리 -> 2, 5, 6
        // 2번 자리 -> 2, 3, 4, 5, 6, 7
        // 3번 자리 -> 2, 4, 5, 6
        // 4번 자리 -> 2, 3, 4, 5, 6, 7
    }
}

 

segments로 주어지는 획수로 만들 수 있는 시간을 출력하는 문제이다.

각 숫자의 획수는 

0 - 6, 1 - 2, 2 - 5, 3 - 5, 4 - 4, 5 - 5, 6 - 6, 7 - 3, 8 - 7, 9 - 6

으로 이를 int[] segmentCnt로 저장한 뒤에

시간과 분을 hh와 mm으로 표기한 뒤에

이들의 값을 획수로 변환하여 총 획수를 구하고

그 획수가 주어진 segments라면 해당하는 시간과 분을 출력하도록 작성했다.