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

ABC370-C Word Ladder


問題へのリンク


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("adbe");
            WillReturn.Add("bcbc");
            //3
            //acbe
            //acbc
            //bcbc
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("abcde");
            WillReturn.Add("abcde");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("afwgebrw");
            WillReturn.Add("oarbrenq");
            //8
            //aawgebrw
            //aargebrw
            //aarbebrw
            //aarbebnw
            //aarbebnq
            //aarbeenq
            //aarbrenq
            //oarbrenq
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

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

        var sb = new System.Text.StringBuilder(InputList[0]);
        char[] TCharArr = InputList[1].ToCharArray();

        int UB = sb.Length - 1;

        var AnswerList = new List<string>();

        // 下がる場合は、左から
        for (int I = 0; I <= UB; I++) {
            if (sb[I] > TCharArr[I]) {
                sb[I] = TCharArr[I];
                AnswerList.Add(sb.ToString());
            }
        }

        // 上がる場合は、右から
        for (int I = UB; 0 <= I; I--) {
            if (sb[I] < TCharArr[I]) {
                sb[I] = TCharArr[I];
                AnswerList.Add(sb.ToString());
            }
        }

        Console.WriteLine(AnswerList.Count);
        AnswerList.ForEach(pX => Console.WriteLine(pX));
    }
}


解説

数値で考えると
1425を
2323に変換となるので、

まず、下がる変換を左から行う。
次に、上がる変換を右から行う。

で解けます。