AtCoderのABC    次のABCの問題へ    前のABCの問題へ

ABC201-C Secret Number


問題へのリンク


C#のソース

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("ooo???xxxx");
            //108
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("o?oo?oxoxo");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("xxxxx?xxxo");
            //15
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        string S = InputList[0];

        var KouhoList = new List<string>();
        for (int I = 0; I <= 9999; I++) {
            KouhoList.Add(I.ToString("0000"));
        }

        for (int I = 0; I <= 9; I++) {
            string CurrStr = I.ToString();
            if (S[I] == 'o') {
                KouhoList.RemoveAll(pX => pX.Contains(CurrStr) == false);
            }
            if (S[I] == 'x') {
                KouhoList.RemoveAll(pX => pX.Contains(CurrStr));
            }
        }
        Console.WriteLine(KouhoList.Count);
    }
}


解説

ToStringメソッドで前ゼロ埋めしてます。