Advertisement
ghostd0g

Untitled

Feb 25th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Exercise4
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Dictionary<string, List<string>> result = new Dictionary<string, List<string>>();
  15.  
  16.             while (true)
  17.             {
  18.                 string input = Console.ReadLine();
  19.  
  20.                 if (input == "end")
  21.                 {
  22.                     break;
  23.                 }
  24.                
  25.                 string pattern = @"([A-Z]{2})([\d]+.[\d]+)([A-Za-z]+)(?=\|)";
  26.  
  27.                 foreach (Match match in Regex.Matches(input, pattern))
  28.                 {
  29.                     List<string> currentWeather = new List<string>();
  30.                     string city = match.Groups[1].Value;
  31.  
  32.                     currentWeather.Add(match.Groups[2].Value);
  33.                     currentWeather.Add(match.Groups[3].Value);
  34.  
  35.                     if (!result.ContainsKey(city))
  36.                     {
  37.                         result.Add(city, currentWeather);
  38.                     }
  39.                     else
  40.                     {
  41.                         result[city] = currentWeather;
  42.                     }
  43.                 }
  44.  
  45.             }
  46.  
  47.             foreach (var city in result.OrderBy(x=>x.Value[0]))
  48.             {
  49.                 double temp = double.Parse(city.Value[0].Replace('.',','));
  50.                 Console.WriteLine($"{city.Key} => {temp:f2} => {city.Value[1]}");
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement