4DM3M

25

Jan 3rd, 2022
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Drafty
  4. {
  5.     class Program
  6.     {
  7.         public static void ReverseHalfes(string source)
  8.         {
  9.             if (source.Length % 2 != 0)
  10.             {
  11.                 Console.WriteLine("Строка должна быть чётной!");
  12.                 return;
  13.             }
  14.  
  15.             string firstHalf = ReverseString(source.Substring(0, source.Length / 2));
  16.             string secondHalf = ReverseString(source.Substring(source.Length / 2, source.Length / 2));
  17.             Console.WriteLine(firstHalf + secondHalf);
  18.         }
  19.  
  20.         public static string ReverseString(string source)
  21.         {
  22.             string result = "";
  23.  
  24.             for (int i = source.Length - 1; i >= 0; i--)
  25.             {
  26.                 result += source[i];
  27.             }
  28.  
  29.             return result;
  30.         }
  31.  
  32.         static void Main(string[] args)
  33.         {
  34.             Console.Write("Введите чётную строку: ");
  35.             ReverseHalfes(Console.ReadLine());
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment