Esempio n. 1
0
        static void Main(string[] args)
        {
            var dict = new Dictionary <string, CityWeather>();

            while (true)
            {
                var input = Console.ReadLine();

                if (input == "end")
                {
                    break;
                }

                var regex = @"([A-Z][A-Z])([0-9]*\.[0-9]*)([A-Za-z]+)\|";

                MatchCollection forecasts = Regex.Matches(input, regex);

                foreach (Match forecast in forecasts)
                {
                    var town = forecast.Groups[1].ToString();

                    CityWeather city = new CityWeather();

                    city.temp    = float.Parse(forecast.Groups[2].Value);
                    city.weather = forecast.Groups[3].Value;

                    if (!dict.ContainsKey(town))
                    {
                        dict.Add(town, city);
                    }
                    else
                    {
                        dict[town] = city;
                    }
                }
            }

            var ordered = dict.OrderBy(x => x.Value.temp);

            foreach (var towns in ordered)
            {
                Console.WriteLine("{0} => {1:f2} => {2}", towns.Key, towns.Value.temp, towns.Value.weather);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                string      iniPath = "../../../config.ini";
                CityWeather weather = new CityWeather(iniPath);
                Console.WriteLine(weather.ToString());
                Console.WriteLine("h - показать город с самой высокой температурой");
                int    number;
                string answer = "y";
                while (answer == "y" || answer == "Y")
                {
                    Console.WriteLine("Выберите город(номер или h)");
                    string str = Console.ReadLine();
                    bool   res = Int32.TryParse(str, out number);
                    if (res)
                    {
                        Console.WriteLine(weather.ShowWeatherByIndex(Convert.ToInt32(str)));
                    }
                    else
                    {
                        switch (str)
                        {
                        case "h":
                            Console.WriteLine("Сейчас мы покажем в каком городе самая высокая температура");
                            Console.WriteLine(weather.SelectHottestCity());
                            break;

                        default: Console.WriteLine("Неверная опция");
                            break;
                        }
                    }
                    Console.WriteLine("Хотите посмотреть погоду в другом городе? Y(да)/N(нет)");
                    answer = Console.ReadLine();
                }
                Console.WriteLine("До свидания");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Dictionary <string, CityWeather> allCities = new Dictionary <string, CityWeather>();

            string pattern = @"(?<cityCode>[A-Z]{2})(?<temp>[0-9]+\.[0-9]*)(?<weather>[A-Za-z]+)";

            while (true)
            {
                string input = Console.ReadLine();

                if (input == "end")
                {
                    break;
                }

                foreach (Match m in Regex.Matches(input, pattern))
                {
                    var city        = m.Groups[1].Value;
                    var cityWeather = new CityWeather();
                    cityWeather.temperatyre = double.Parse(m.Groups[2].Value);
                    cityWeather.weather     = m.Groups[3].Value;

                    if (!allCities.ContainsKey(city))
                    {
                        allCities.Add(city, cityWeather);
                    }
                    else
                    {
                        allCities[city] = cityWeather;
                    }
                }
            }

            foreach (var city in allCities.OrderBy(x => x.Value.temperatyre))
            {
                Console.WriteLine($"{city.Key} => {city.Value.temperatyre:F2} => {city.Value.weather}");
            }
        }