AtCoderのPAST    次のPASTの問題へ

第1回PAST C 3番目


問題へのリンク


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 18 25 20 9 13");
            //18
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("95 96 97 98 99 100");
            //98
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("19 92 3 35 78 1");
            //35
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        Array.Sort(wkArr, (pA, pB) => pB.CompareTo(pA));
        Console.WriteLine(wkArr[2]);
    }
}


解説

ArrayのSortメソッドで降順ソートし、
添字で3番目の値を取得してます。