Advertisement
OldBeliver

Collection_01ver01

Apr 2nd, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace OlimpicCapitals_ver01
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool exit = false;
  14.             string userInput;
  15.  
  16.             Dictionary<int, string> olympicCapitals = GetDictionary();            
  17.            
  18.             while (exit == false)
  19.             {
  20.                 Console.WriteLine($"Олимпийские столицы за последние 20 лет:\n");
  21.                 Console.Write($"Введите год проведения Олимпийских Игр с 2000 по 2028: ");
  22.                 userInput = Console.ReadLine();
  23.  
  24.                 switch (userInput)
  25.                 {
  26.                     case "exit":
  27.                         exit = true;
  28.                         break;
  29.                     default:
  30.                         DisplayInfo(userInput, olympicCapitals);
  31.                         break;
  32.                 }
  33.                 Console.Write($"нажмите для продолжения ...");
  34.                 Console.ReadKey();
  35.                 Console.Clear();
  36.             }
  37.         }
  38.  
  39.         static Dictionary<int, string> GetDictionary()
  40.         {
  41.             Dictionary<int, string> olympicCapitals = new Dictionary<int, string>();
  42.  
  43.             olympicCapitals.Add(2000, "Сидней, Австралия");
  44.             olympicCapitals.Add(2002, "Солт-Лейк-Сити, США");
  45.             olympicCapitals.Add(2004, "Афины, Греция");
  46.             olympicCapitals.Add(2006, "Турин, Италия");
  47.             olympicCapitals.Add(2008, "Пекин, Китай");
  48.             olympicCapitals.Add(2010, "Ванкувер, Канада");
  49.             olympicCapitals.Add(2012, "Лондон, Великобритания");
  50.             olympicCapitals.Add(2014, "Сочи, Россия");
  51.             olympicCapitals.Add(2016, "Рио-же-Жанейро, Бразилия");
  52.             olympicCapitals.Add(2018, "Пхёнчхан, Южная Корея");
  53.             olympicCapitals.Add(2020, "перенесены из-за COVID-19");
  54.             olympicCapitals.Add(2022, "Пекин, Китай");
  55.             olympicCapitals.Add(2024, "Париж, Франция");
  56.             olympicCapitals.Add(2026, "Милан, Италия");
  57.             olympicCapitals.Add(2028, "Лос-Анджелес, США");
  58.  
  59.             return olympicCapitals;
  60.         }
  61.  
  62.         static void DisplayInfo(string userInput, Dictionary<int, string> olympicCapitals)
  63.         {
  64.             int year;
  65.             bool isNumber = int.TryParse(userInput, out year);
  66.  
  67.             if (isNumber == true)
  68.             {
  69.                 if (olympicCapitals.ContainsKey(year))
  70.                 {
  71.                     Console.WriteLine($"В {year} году Олимпийские игры - {olympicCapitals[year]}");
  72.                 }
  73.                 else
  74.                 {
  75.                     Console.WriteLine($"В этот год Олимпиады не было");
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 Console.WriteLine($"какое-то странное число");
  81.             }
  82.         }
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement