典型90問    次の典型90問へ    前の典型90問へ

典型90問 027 Sign Up Requests (★2)


問題へのリンク


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("5");
            WillReturn.Add("e869120");
            WillReturn.Add("atcoder");
            WillReturn.Add("e869120");
            WillReturn.Add("square1001");
            WillReturn.Add("square1001");
            //1
            //2
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("taro");
            WillReturn.Add("hanako");
            WillReturn.Add("yuka");
            WillReturn.Add("takashi");
            //1
            //2
            //3
            //4
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            WillReturn.Add("square869120");
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string[] SArr = InputList.Skip(1).ToArray();

        var SSet = new HashSet<string>();
        for (int I = 0; I <= SArr.GetUpperBound(0); I++) {
            if (SSet.Add(SArr[I])) {
                Console.WriteLine(I + 1);
            }
        }
    }
}


解説

HashSetで重複判定してます。