SRM395 DIV2 Level.1

今日も元気に頭が悪いgray coderの私です。
せめてgreen目指したいよね!ということでこれからも頑張りたいところです。


0,1,4,9で構成される数字のn番目を求めろって問題。
こんなもんですかね?

using System;
using System.Collections.Generic;
using System.Text;


public class SquareDigitNumbers
{
    bool isSquare(int num)
    {
        String s = num.ToString();

        foreach(char i in s)
        {
            if (i != '1' && i != '0' && i != '4' && i != '9')
            {
                return false;
            }
        }
        return true;
    }


    public int getNumber(int n)
    {
        int count = 0;
        int num = 0;

        while (count < n)
        {
            num++;
            if (isSquare(num))
            {
                count++;
            }
        }
        return num;
    }
}