using system;
using system.Collections;
using system.Collections.Generic;
using system.IO;
using system.Linq;
using system.Text.RegularExpressions;
/* Don't change anything here.
* Do not add any other imports. You need to write
* this program using only these libraries
*/
namespace ProgramNamespace
{
/* You may add helper classes here if necessary */
public class Program
{
//public static List<String> processData(IList<string> lines)
public static List<String> processData(IEnumerable<string> lines)
{
/*
* Do not make any changes outside this method.
*
* Modify this method to process `array` as indicated
* in the question. At the end, return the size of the
* array.
*
* Do not print anything in this method
*
* Submit this entire program (not just this function)
* as your answer
*/
IList<string> newlines =
new List<string>
(lines
);
IList<string> IElines =
new List<string>
(lines
);
List<String> retVal =
new List<String>
();
List<String> retValLibrary =
new List<String>
();
//var retValLibrary = new Dictionary<string, string>();
//var myList = new List<KeyValuePair<string, int>>();
List<int> versions =
new List<int>
();
//Int32[] versions = new Int32[lines.Count];
//Int32[] librarycnt = new Int32[lines.Count];
for (int i = 0; i < IElines.Count(); i++)
{
//versions[i] = Convert.ToInt32(Regex.Match(lines[i], @"\d+").Value);
versions.Add(Convert.ToInt32(Regex.Match(IElines[i], @"\d+").Value));
}
Top:
int min = versions.Min();
int ii = 0;
foreach (var line in newlines)
{
string[] parts = line.Split(',');
if (line.Contains(min.ToString()))
{
if (!retVal.Contains(parts[0]) && CountValue(newlines, parts[1])>1) //&& !retVal.Contains(parts[0]) && cnt==0)
{
retValLibrary.Add(parts[1]);
retVal.Add(parts[0]);
//cnt++;
newlines.Remove(line.ToString());
//versions = versions.Where(val => val != min).ToArray();
versions.RemoveAt(ii);
goto Top;
}
else if(CountValue(IElines, parts[1])==1)
{
newlines.Remove(line.ToString());
//versions = versions.Where(val => val != min).ToArray();
versions.RemoveAt(ii);
goto Top;
}
}
ii++;
}
return retVal;
}
static int CountValue(IList<string> list, string valueToFind)
{
int cnt = 0;
cnt = ((from temp in list where temp.Contains(valueToFind) select temp).Count());
return cnt;
}
static void Main(string[] args)
{
try
{
//List<String> retVal = processData(File.ReadAllLines("input.txt"));
//File.WriteAllLines("output.txt", retVal);
string line;
var inputLines =
new List<String>
();
while ((line = Console.ReadLine()) != null)
{
line = line.Trim();
if (line != "")
inputLines.Add(line);
}
var retVal = processData(inputLines);
foreach (var res in retVal)
Console.WriteLine(res);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
//Console.WriteLine("{0}", f2());
Console.ReadLine();
}
}
}