yanchevilian

3. Characters in Range

Feb 12th, 2021 (edited)
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _3._Characters_in_Range
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             char firstSymbol = char.Parse(Console.ReadLine());
  11.             char secondSymbol = char.Parse(Console.ReadLine());
  12.             List<string> result = FindSymbolsBetweenChars(firstSymbol, secondSymbol);
  13.             foreach (var currentSymbol in result)
  14.             {
  15.                 Console.Write(currentSymbol + " ");
  16.             }
  17.         }
  18.  
  19.         private static List<string> FindSymbolsBetweenChars(char firstSymbol, char secondSymbol)
  20.         {
  21.             List<string> charSymbols = new List<string>();
  22.  
  23.             int firstCharNumber = Convert.ToInt32(firstSymbol);
  24.             int secondCharNumber = Convert.ToInt32(secondSymbol);
  25.  
  26.             if (firstCharNumber < secondSymbol)
  27.             {
  28.                 for (int i = firstSymbol + 1; i < secondSymbol; i++)
  29.                 {
  30.                     char currentChar = (char)i;
  31.                     string charr = currentChar.ToString();
  32.                     charSymbols.Add(charr);
  33.                 }
  34.             }
  35.             else if (secondSymbol < firstSymbol)
  36.             {
  37.                 for (int i = secondSymbol + 1; i < firstSymbol; i++)
  38.                 {
  39.                     char currentChar = (char)i;
  40.                     string charr = currentChar.ToString();
  41.                     charSymbols.Add(charr);
  42.                 }
  43.             }
  44.             return charSymbols;
  45.         }
  46.     }
  47. }
  48.  
Add Comment
Please, Sign In to add comment