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

ARC-049-A "強調"

■■■問題■■■

文字列Sと、非負整数A,B,C,Dが与えられます。
Sの、A,B,C,D文字目の後ろにダブルクオーテーション"を挿入した文字列を出力してください。
ただし、0文字目の後ろというのは、文字列の先頭を指すこととします。

■■■入力■■■

S
A B C D

●1行目には文字列 S (3 <= |S| <= 100) が与えられる。
●2行目には、非負整数 A,B,C,D (0 <= A < B < C < D <= |S|) が空白区切りで与えられる。
●|S| とは、Sの長さである。
●Sはすべて英字とアンダーバー(_)からなる。

■■■出力■■■

ダブルクオーテーション"を挿入した文字列を出力する。


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("MinnnahaNakayoshi");
            WillReturn.Add("0 6 8 17");
            //"Minnna"ha"Nakayoshi"
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("Niwawo_Kakemeguru_Chokudai");
            WillReturn.Add("11 17 18 26");
            //Niwawo_Kake"meguru"_"Chokudai"
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("___");
            WillReturn.Add("0 1 2 3");
            //"_"_"_"
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];
        int[] wkArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        int A = wkArr[0];
        int B = wkArr[1];
        int C = wkArr[2];
        int D = wkArr[3];

        string Answer = S;
        Answer = Answer.Insert(D, @"""");
        Answer = Answer.Insert(C, @"""");
        Answer = Answer.Insert(B, @"""");
        Answer = Answer.Insert(A, @"""");
        Console.WriteLine(Answer);
    }
}


解説

文字列の後ろから、String.Insertメソッドを使ってます。