Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Globalization;
- public class Program
- {
- public static void Main()
- {
- Dictionary<string,Dictionary<double,string>> cityTempWeather = new Dictionary<string,Dictionary<double,string>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end")
- {
- break;
- }
- string regex = @"((?<town>[A-Z]{2})(?<temp>\d+\.\d+)(?<weather>[A-Za-z]+))\|";
- if (Regex.IsMatch(input,regex))
- {
- Match match = Regex.Match(input,regex);
- string city = match.Groups["town"].Value;
- double temperature = double.Parse(match.Groups["temp"].Value);
- string typeOfWeather = match.Groups["weather"].Value;
- if (char.IsLower(typeOfWeather[0]))
- {
- typeOfWeather = typeOfWeather.ToLower();
- }
- else
- {
- typeOfWeather = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(typeOfWeather);
- }
- if (!cityTempWeather.ContainsKey(city))
- {
- cityTempWeather.Add(city, new Dictionary<double,string>());
- cityTempWeather[city].Add(temperature,typeOfWeather);
- }
- else
- {
- cityTempWeather[city]=new Dictionary<double,string>();
- cityTempWeather[city].Add(temperature,typeOfWeather);
- }
- }
- }
- foreach (var kvp in cityTempWeather.OrderBy(x=>x.Value.Keys.Average()))
- {
- string city = kvp.Key;
- foreach (var kvpValue in kvp.Value)
- {
- double temperature = kvpValue.Key;
- string type = kvpValue.Value;
- Console.WriteLine("{0} => {1:f2} => {2}",city,temperature,type);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment