Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Nikola-Andreev/36c2ef28f0153abb92fc44d6c40ca783 to your computer and use it in GitHub Desktop.
Save Nikola-Andreev/36c2ef28f0153abb92fc44d6c40ca783 to your computer and use it in GitHub Desktop.
04. Population Aggregation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;
class Programa
{
static void Main(string[] args)
{
string[] input = Console.ReadLine().Split('\\').ToArray();
SortedDictionary<string, int> countries = new SortedDictionary<string, int>();
Dictionary<long, string> cityes = new Dictionary<long, string>();
while (input[0]!="stop")
{
char[] first = input[0].ToCharArray();
string clearWord = string.Empty;
for (int i = 0; i < first.Length; i++)
{
if (char.IsLetter(first[i]))
{
clearWord += first[i];
}
}
if (char.IsLower(clearWord.First()))
{
if (!cityes.ContainsValue(clearWord))
{
cityes.Add(long.Parse(input[2]), clearWord);
}
}
else
{
if (countries.ContainsKey(clearWord))
{
countries[clearWord]++;
}
else
{
countries.Add(clearWord, 1);
}
}
char[] second = input[1].ToCharArray();
string clearSecondWord = string.Empty;
for (int i = 0; i < second.Length; i++)
{
if (char.IsLetter(second[i]))
{
clearSecondWord += second[i];
}
}
if (char.IsLower(clearSecondWord.First()))
{
if (!cityes.ContainsValue(clearSecondWord))
{
cityes.Add(long.Parse(input[2]), clearSecondWord);
}
}
else
{
if (countries.ContainsKey(clearSecondWord))
{
countries[clearSecondWord]++;
}
else
{
countries.Add(clearSecondWord, 1);
}
}
input = Console.ReadLine().Split('\\').ToArray();
}
foreach (var item in countries)
{
Console.WriteLine("{0} -> {1}",item.Key,item.Value);
}
int max = Math.Min(3, cityes.Count);
int counter = 0;
var l = cityes.OrderByDescending(b => b.Key);
foreach (var item in l)
{
Console.WriteLine("{0} -> {1}",item.Value,item.Key);
counter++;
if (counter==max)
{
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment