Advertisement
TeMePyT

Untitled

Jun 3rd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Weather
  7. {
  8.     class Weather
  9.     {
  10.         public double Temperature { get; set; }
  11.         public string weatherType { get; set; }
  12.     }
  13.  
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             string input = Console.ReadLine();
  19.             string pattern = @"(?<town>[A-Z]{2})(?<temp>[0-9]+\.[0-9]+)(?<weather>[A-Za-z]+)\|";
  20.             Dictionary<string, Weather> forecast = new Dictionary<string, Weather>();
  21.             while (input != "end")
  22.             {
  23.                 if (Regex.IsMatch(input, pattern))
  24.                 {
  25.                     Match match = Regex.Match(input, pattern);
  26.                     string town = match.Groups["town"].ToString();
  27.                     double temp = double.Parse(match.Groups["temp"].ToString());
  28.                     string weatherType = match.Groups["weather"].ToString();
  29.                     Weather weather = new Weather();
  30.                     weather.Temperature = temp;
  31.                     weather.weatherType = weatherType;
  32.                     forecast[town] = weather;
  33.                 }
  34.                 input = Console.ReadLine();
  35.             }
  36.  
  37.             foreach (var town in forecast.OrderBy(x => x.Value.Temperature))
  38.             {
  39.                 Console.WriteLine($"{town.Key} => {town.Value.Temperature:f2} => {town.Value.weatherType}");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement