AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC348-C Colorful Beans
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("100 1");
WillReturn.Add("20 5");
WillReturn.Add("30 5");
WillReturn.Add("40 1");
//40
}
else if (InputPattern == "Input2") {
WillReturn.Add("10");
WillReturn.Add("68 3");
WillReturn.Add("17 2");
WillReturn.Add("99 2");
WillReturn.Add("92 4");
WillReturn.Add("82 4");
WillReturn.Add("10 3");
WillReturn.Add("100 2");
WillReturn.Add("78 1");
WillReturn.Add("3 1");
WillReturn.Add("35 4");
//35
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct BeanDef
{
internal long Aji;
internal long Color;
}
static List<BeanDef> mBeanList = new List<BeanDef>();
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
BeanDef WillAdd;
WillAdd.Aji = wkArr[0];
WillAdd.Color = wkArr[1];
mBeanList.Add(WillAdd);
}
var AnswerList = new List<long>();
foreach (var EachItem in mBeanList.GroupBy(pX => pX.Color)) {
AnswerList.Add(EachItem.Min(pX => pX.Aji));
}
Console.WriteLine(AnswerList.Max());
}
}
解説
ColorでGroupByして、味の最小値のListを作ってます。