AtCoderのARC
   次のARCの問題へ
   前のARCの問題へ
ARC027-B 大事な数なのでZ回書きまLた。
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("4");
            WillReturn.Add("1XYX");
            WillReturn.Add("1Z48");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("XXX");
            WillReturn.Add("YYY");
            //9
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6");
            WillReturn.Add("PRBLMB");
            WillReturn.Add("ARC027");
            //90
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }
    static void Main()
    {
        List<string> InputList = GetInputList();
        string S1 = InputList[1];
        string S2 = InputList[2];
        int UB = S1.Length - 1;
        Predicate<char> IsAlpha = (pChar) => ('A' <= pChar && pChar <= 'Z');
        // 上下を、見て確定文字の確定
        for (int I = 0; I <= UB; I++) {
            char C1 = S1[I];
            char C2 = S2[I];
            if (C1 == C2) continue;
            if (IsAlpha(C1) && IsAlpha(C2) == false) {
                S1 = S1.Replace(C1, C2);
                S2 = S2.Replace(C1, C2);
            }
            else if (IsAlpha(C1) == false && IsAlpha(C2)) {
                S1 = S1.Replace(C2, C1);
                S2 = S2.Replace(C2, C1);
            }
            else if (IsAlpha(C1) && IsAlpha(C2)) {
                S1 = S1.Replace(C1, C2);
                S2 = S2.Replace(C1, C2);
            }
        }
        // ゼロが使用可能な文字と、ゼロが使用不可な文字で積の法則
        var NotZeroSet = new HashSet<char>();
        var MayZeroSet = new HashSet<char>();
        if (IsAlpha(S1[0])) NotZeroSet.Add(S1[0]);
        for (int I = 1; I <= S1.Length - 1; I++) {
            if (IsAlpha(S1[I]) == false) continue;
            if (NotZeroSet.Contains(S1[I]) == false) {
                MayZeroSet.Add(S1[I]);
            }
        }
        long Answer = 1;
        // ゼロが使用不可な文字
        foreach (char EachChar in NotZeroSet) {
            Answer *= 9;
        }
        // ゼロが使用可能な文字
        foreach (char EachChar in MayZeroSet) {
            Answer *= 10;
        }
        Console.WriteLine(Answer);
    }
}
解説
まず、確定可能な数字を確定させます。
次に、
0が使用可能な文字と
0が使用不可な文字が
それぞれ何通りあるかを求め
積の法則を使ってます。