Advertisement
wingman007

Task372

Nov 20th, 2023
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. namespace KrushkovTask372
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             string[] cities = new string[5];
  8.             InputCities(cities);
  9.  
  10.             string[] filtered = new string[5];
  11.             filtered = FilterBySubstring(cities, "град");
  12.             foreach (string s in filtered)
  13.             {
  14.                 Console.WriteLine(s);
  15.             }
  16.         }
  17.  
  18.         static void InputCities(string[] cities)
  19.         {
  20.             for (int i = 0; i < cities.Length; i++)
  21.             {
  22.                 Console.Write("Please enter city[{0}]: ", i);
  23.                 cities[i] = Console.ReadLine();
  24.             }
  25.         }
  26.  
  27.         static string[] FilterBySubstring(string[] cities, string substring)
  28.         {
  29.             string[] filtered = new string[cities.Length];
  30.             for (int i = 0; i < cities.Length; i++)
  31.             {
  32.                 if (cities[i].Contains(substring))
  33.                 {
  34.                     filtered[i] = cities[i];
  35.                 }
  36.             }
  37.             return filtered;
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement