Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Numerics;
- using System.Text.RegularExpressions;
- namespace C_
- {
- class City
- {
- public string Name { get; set; }
- public double Temp { get; set; }
- public string Weather { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine();
- var result = new List<City>();
- var pattern = @"([A-Z]{2})(\d+\.\d+)([A-Z]?[a-z]+|[a-z]?[A-Z]+)[|]";
- while (input!="end")
- {
- var cuurentinfo = input;
- bool isMatch = Regex.IsMatch(cuurentinfo, pattern);
- if (isMatch)
- {
- Match match = Regex.Match(cuurentinfo, pattern);
- var name = match.Groups[1].Value;
- var temperature = double.Parse(match.Groups[2].Value);
- var weather = match.Groups[3].Value;
- var isFound = result.FirstOrDefault(x => x.Name == name);
- if (isFound != null)
- {
- isFound.Temp = temperature;
- isFound.Weather = weather;
- }
- else
- {
- var city = new City
- {
- Name = name,
- Temp = temperature,
- Weather = weather
- };
- result.Add(city);
- }
- }
- input = Console.ReadLine();
- }
- foreach (var city in result.OrderBy(x=>x.Temp))
- {
- Console.WriteLine($"{city.Name} => {city.Temp:F2} => {city.Weather}");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment