본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 1475 방 번호

by 왹져박사 2023. 11. 10.
728x90

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

 

1475번: 방 번호

첫째 줄에 다솜이의 방 번호 N이 주어진다. N은 1,000,000보다 작거나 같은 자연수이다.

www.acmicpc.net

using System;
using System.IO;

namespace B1475
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            int n = int.Parse(sr.ReadLine());
            int[] arr = new int[10];
            int set = 1;

            while (n > 0)
            {
                int m = n % 10;
                if (arr[m] == set)
                {
                    if (m == 6 && arr[9] < set) arr[9]++;
                    else if (m == 9 && arr[6] < set) arr[6]++;
                    else
                    {
                        arr[m]++;
                        set++;
                    }
                }
                else arr[m]++;
                n /= 10;
            }
            sw.Write(set);
            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 9655 돌 게임  (0) 2023.11.11
[ BOJ/C# ] 1065 한수  (0) 2023.11.08
[ BOJ/C# ] 4673 셀프 넘버  (0) 2023.11.07
[ BOJ/C# ] 2941 크로아티아 알파벳  (0) 2023.11.06
[ BOJ/C# ] 1789 수들의 합  (0) 2023.11.06