class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press 0 to exit");
Dictionary<int, Structure> dict = new Dictionary<int, Structure>();
string readLine;
while ("0" != (readLine = Console.ReadLine()))
{
string line = readLine;
KeyValuePair<int, Structure> firstOrDefault = dict.FirstOrDefault(ob => ob.Value.Word == line);
Structure val = new Structure { Count = firstOrDefault.Value.Count + 1, Word = readLine };
int dictionaryCount = dict.Count;
if (!firstOrDefault.Equals(default(KeyValuePair<int, Structure>)))
{
dict.Remove(firstOrDefault.Key);
dictionaryCount = firstOrDefault.Key;
}
dict.Add(dictionaryCount, val);
}
Structure[] structures = dict.Values.ToArray();
Array.Sort(structures);
foreach (var structure in structures)
{
Console.WriteLine("Word : {0} -> Count : {1}",structure.Word ,structure.Count);
}
Console.ReadKey();
}
struct Structure : IComparable
{
public string Word { get; set; }
public int Count { get; set; }
public int CompareTo(object obj)
{
return Word.CompareTo(((Structure)obj).Word);
}
}
}