トップページに戻る    次の競技プログラミングの問題へ    前の競技プログラミングの問題へ

ARC-046-A ゾロ目数

■■■問題■■■

すべての桁の数字が同じであるような正の整数をゾロ目数と呼ぶことにします。
小さい方からN番目のゾロ目数を求めてください。

■■■入力■■■

N

1行目には、整数N (1 <= N <= 50) が与えられる。

■■■出力■■■

小さい方からN番目のゾロ目数を出力せよ。出力の末尾には改行を入れること。


C#のソース

using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("11");
            //22
            //ゾロ目数を小さい方から列挙すると、
            //1,2,3,4,5,6,7,8,9,11,22,・・・ となります。
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("50");
            //555555
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        int Cnt = 0;
        for (int I = 1; I < int.MaxValue; I++) {
            for (char J = '1'; J <= '9'; J++) {
                if (++Cnt == N) {
                    Console.WriteLine(new string(J, I));
                    return;
                }
            }
        }
    }
}


解説

制約が緩いので、ゾロ目数を順番に作成してます。