Arxero

Untitled

Nov 19th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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 _04.Weather
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var listOfCities = new Dictionary<string,CityWheather>();
  15.             var pattern = new Regex(@"([A-Z][A-Z])(\d{2}\.\d{1,})(\w+\w)\|");
  16.             while (true)
  17.             {
  18.                 var input = Console.ReadLine();
  19.                 if (input=="end")
  20.                 {
  21.                     break;
  22.                 }
  23.                 foreach (Match match in pattern.Matches(input))
  24.                 {
  25.                     string name = match.Groups[1].Value;
  26.                     var city = new CityWheather(){
  27.                     temperature = (double.Parse(match.Groups[2].Value)),
  28.                     wheather = match.Groups[3].Value};
  29.                     listOfCities[name]=(city);
  30.                 }
  31.             }
  32.             var ordered = listOfCities.OrderBy(c => c.Value.temperature);
  33.             foreach (var city in ordered)
  34.             {
  35.                 Console.WriteLine($"{city.Key} => {city.Value.temperature:f2} => {city.Value.wheather}");
  36.             }
  37.         }
  38.     }
  39.     public class CityWheather
  40.     {
  41.         public double temperature { get; set; }
  42.         public string wheather { get; set; }
  43.  
  44.     }
  45. }
Add Comment
Please, Sign In to add comment