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.RegularExpressions;
- namespace P04Weather
- {
- class WeatherInformation
- {
- public double Temperature { get; set; }
- public string Weather { get; set; }
- public WeatherInformation(double temperature, string weather)
- {
- Temperature = temperature;
- Weather = weather;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //List<string> inputs = new List<string>();
- Dictionary<string, WeatherInformation> townWeather = new Dictionary<string, WeatherInformation>();
- Regex regex = new Regex(@"(?<town>[A-Z]{2})(?<temperature>[0-9]{1,}\.[0-9]{1,})(?<weather>\w+)(?=\|)");
- MatchCollection matches;
- while (true)
- {
- string currentInput = Console.ReadLine();
- if (currentInput == "end")
- {
- break;
- }
- if (regex.IsMatch(currentInput))
- {
- Match match = regex.Match(currentInput);
- if (townWeather.ContainsKey(match.Groups["town"].ToString()) == false)
- {
- WeatherInformation currentInfo = new WeatherInformation(
- double.Parse(match.Groups["temperature"].ToString()),
- match.Groups["weather"].ToString());
- townWeather.Add(match.Groups["town"].ToString(), currentInfo);
- }
- else
- {
- //WeatherInformation currentInfo = new WeatherInformation( // ima li nujda it "new" po-skoro ne, no ne znam kak inache da go napravq
- // double.Parse(match.Groups["temperature"].ToString()),
- // match.Groups["weather"].ToString());
- //townWeather[match.Groups["town"].ToString()] = currentInfo;
- string weather = match.Groups["weather"].ToString();
- double temperature = double.Parse(match.Groups["temperature"].ToString());
- townWeather[match.Groups["town"].ToString()].Weather = weather;
- townWeather[match.Groups["town"].ToString()].Temperature = temperature;
- }
- }
- }
- foreach (var kvp in townWeather.Values.OrderBy(t => t.Temperature))
- {
- }
- //Console.WriteLine($"{currentMatch.Groups["town"]} => {currentMatch.Groups["temperature"]} => {currentMatch.Groups["weather"]}");
- //main ends here
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement