Advertisement
Guest User

weather

a guest
Feb 22nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 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.         static void Main(string[] args)
  11.         {
  12.           string input=Console.ReadLine();
  13.  
  14.             Dictionary<string, Dictionary<double, string>> info = new Dictionary<string, Dictionary<double, string>>();
  15.             while (input != "end")
  16.             {
  17.                 string patern = @"([A-Z]{2})([0-5]{2}\.[0-5]{1,2})([A-za-z]+)\|";
  18.                 MatchCollection match = Regex.Matches(input, patern);
  19.  
  20.                 if (Regex.IsMatch(input,patern)==false)
  21.                 {
  22.                     input = Console.ReadLine();
  23.                     continue;
  24.                 }
  25.  
  26.                 string city = "";
  27.                 string temp = "";
  28.                 string weather = "";
  29.                 foreach (Match item in match)
  30.                 {
  31.                     city = item.Groups[1].Value;
  32.                     temp = item.Groups[2].Value;
  33.                     weather = item.Groups[3].Value;
  34.                 }
  35.                 double temperature = double.Parse(temp);
  36.                 string tempweth = weather.ToLower();
  37.              
  38.                 if (info.ContainsKey(city) == false)
  39.                 {
  40.                     var helper = new Dictionary<double, string>();
  41.                     helper.Add(temperature, weather);
  42.                     info.Add(city, helper);
  43.                 }
  44.                 else
  45.                 {
  46.                     info[city].Clear();
  47.                     info[city].Add(temperature, weather);
  48.                 }
  49.                 input = Console.ReadLine();
  50.             }
  51.             foreach (var item in info.OrderBy(x=>x.Value.Keys.Average()))
  52.             {
  53.                 Console.Write($"{item.Key} => {item.Value.Keys.Average():f2} => ");
  54.                 foreach (var weath in item.Value)
  55.                 {
  56.                     Console.WriteLine($"{weath.Value}");
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement