Advertisement
fbinnzhivko

Untitled

Jun 10th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7. using System.Globalization;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10.  
  11. class Programa
  12. {
  13.     static void Main(string[] args)
  14.     {
  15.         string[] input = Console.ReadLine().Split('\\').ToArray();
  16.         SortedDictionary<string, int> countries = new SortedDictionary<string, int>();
  17.         Dictionary<long, string> cityes = new Dictionary<long, string>();
  18.  
  19.         while (input[0]!="stop")
  20.         {
  21.             char[] first = input[0].ToCharArray();
  22.             string clearWord = string.Empty;
  23.             for (int i = 0; i < first.Length; i++)
  24.             {
  25.                 if (char.IsLetter(first[i]))
  26.                 {
  27.                     clearWord += first[i];
  28.                 }
  29.             }
  30.             if (char.IsLower(clearWord.First()))
  31.             {
  32.                 if (!cityes.ContainsValue(clearWord))
  33.                 {
  34.                     cityes.Add(long.Parse(input[2]), clearWord);
  35.                 }
  36.                
  37.             }
  38.             else
  39.             {
  40.                 if (countries.ContainsKey(clearWord))
  41.                 {
  42.                     countries[clearWord]++;
  43.                 }
  44.                 else
  45.                 {
  46.                     countries.Add(clearWord, 1);
  47.                 }              
  48.             }
  49.             char[] second = input[1].ToCharArray();
  50.             string clearSecondWord = string.Empty;
  51.             for (int i = 0; i < second.Length; i++)
  52.             {
  53.                 if (char.IsLetter(second[i]))
  54.                 {
  55.                     clearSecondWord += second[i];
  56.                 }
  57.             }
  58.             if (char.IsLower(clearSecondWord.First()))
  59.             {
  60.                 if (!cityes.ContainsValue(clearSecondWord))
  61.                 {
  62.                     cityes.Add(long.Parse(input[2]), clearSecondWord);
  63.                 }              
  64.             }
  65.             else
  66.             {
  67.                 if (countries.ContainsKey(clearSecondWord))
  68.                 {
  69.                     countries[clearSecondWord]++;
  70.                 }
  71.                 else
  72.                 {
  73.                     countries.Add(clearSecondWord, 1);
  74.                 }
  75.             }
  76.             input = Console.ReadLine().Split('\\').ToArray();
  77.         }
  78.         foreach (var item in countries)
  79.         {
  80.             Console.WriteLine("{0} -> {1}",item.Key,item.Value);
  81.         }
  82.         int max = Math.Min(3, cityes.Count);
  83.         int counter = 0;
  84.         var l = cityes.OrderByDescending(b => b.Key);
  85.         foreach (var item in l)
  86.         {
  87.             Console.WriteLine("{0} -> {1}",item.Value,item.Key);
  88.             counter++;
  89.             if (counter==max)
  90.             {
  91.                 break;
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement