Advertisement
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;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace Weather
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Regex p2 = new Regex(@"([A-Z]{2})(\d+\.\d+)([A-Za-z]+)(?=\|)");
- var dict = new Dictionary<string, SortedDictionary<float, string>>();
- while (input != "end")
- {
- Match m = p2.Match(input);
- if (m.Success)
- {
- string city = m.Groups[1].Value;
- float temperature = float.Parse(m.Groups[2].Value);
- string weather = m.Groups[3].Value;
- if (dict.ContainsKey(city))
- {
- dict[city] = new SortedDictionary<float, string> { { temperature, weather } };
- }
- else
- {
- dict.Add(city, new SortedDictionary<float, string> { { temperature, weather } });
- }
- }
- input = Console.ReadLine();
- }
- //(var item in dict.OrderBy(x => x.Value.temp))
- dict = dict.OrderBy(x => x.Value.First().Key).ToDictionary(x => x.Key, x => x.Value);
- foreach (var item in dict)
- {
- Console.Write(item.Key + " => ");
- foreach (var i2 in item.Value)
- {
- Console.Write(i2.Key + " => " +i2.Value);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement