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.Threading.Tasks;
- namespace OlimpicCapitals_ver01
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = false;
- string userInput;
- Dictionary<int, string> olympicCapitals = GetDictionary();
- while (exit == false)
- {
- Console.WriteLine($"Олимпийские столицы за последние 20 лет:\n");
- Console.Write($"Введите год проведения Олимпийских Игр с 2000 по 2028: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "exit":
- exit = true;
- break;
- default:
- DisplayInfo(userInput, olympicCapitals);
- break;
- }
- Console.Write($"нажмите для продолжения ...");
- Console.ReadKey();
- Console.Clear();
- }
- }
- static Dictionary<int, string> GetDictionary()
- {
- Dictionary<int, string> olympicCapitals = new Dictionary<int, string>();
- olympicCapitals.Add(2000, "Сидней, Австралия");
- olympicCapitals.Add(2002, "Солт-Лейк-Сити, США");
- olympicCapitals.Add(2004, "Афины, Греция");
- olympicCapitals.Add(2006, "Турин, Италия");
- olympicCapitals.Add(2008, "Пекин, Китай");
- olympicCapitals.Add(2010, "Ванкувер, Канада");
- olympicCapitals.Add(2012, "Лондон, Великобритания");
- olympicCapitals.Add(2014, "Сочи, Россия");
- olympicCapitals.Add(2016, "Рио-же-Жанейро, Бразилия");
- olympicCapitals.Add(2018, "Пхёнчхан, Южная Корея");
- olympicCapitals.Add(2020, "перенесены из-за COVID-19");
- olympicCapitals.Add(2022, "Пекин, Китай");
- olympicCapitals.Add(2024, "Париж, Франция");
- olympicCapitals.Add(2026, "Милан, Италия");
- olympicCapitals.Add(2028, "Лос-Анджелес, США");
- return olympicCapitals;
- }
- static void DisplayInfo(string userInput, Dictionary<int, string> olympicCapitals)
- {
- int year;
- bool isNumber = int.TryParse(userInput, out year);
- if (isNumber == true)
- {
- if (olympicCapitals.ContainsKey(year))
- {
- Console.WriteLine($"В {year} году Олимпийские игры - {olympicCapitals[year]}");
- }
- else
- {
- Console.WriteLine($"В этот год Олимпиады не было");
- }
- }
- else
- {
- Console.WriteLine($"какое-то странное число");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement