Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _4._Weather
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, KeyValuePair<double, string>> wheater = new Dictionary<string, KeyValuePair<double, string>>();
- while (true)
- {
- string forecast = Console.ReadLine();
- if (forecast == "end")
- {
- break;
- }
- string pattern = @"([A-Z]{2})(\d+.\d+)([a-zA-Z]+)\|";
- Regex regex = new Regex(pattern);
- Match match = regex.Match(forecast);
- if (!match.Success)
- {
- continue;
- }
- string city = match.Groups[1].ToString();
- double temperature = double.Parse(match.Groups[2].ToString());
- string KindOfWheather = match.Groups[3].ToString();
- if (!wheater.ContainsKey(city))
- {
- wheater.Add(city, new KeyValuePair<double, string>(temperature, KindOfWheather));
- }
- else
- {
- wheater[city] = new KeyValuePair<double, string>(temperature, KindOfWheather);
- }
- }
- foreach (var city in wheater.OrderBy(x => x.Value.Key))
- {
- Console.WriteLine($"{city.Key} => {city.Value.Key:F2} => {city.Value.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment