Advertisement
mlmisha

8.2.2

Apr 5th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. namespace lab
  3. {
  4.     class MainClass
  5.     {
  6.         public static void Main(string[] args)
  7.         {
  8.             Console.WriteLine("Введите текст");
  9.             string c = Console.ReadLine();
  10.             string v = c;
  11.             int t = 1;
  12.             int r = 0;
  13.             int i = 0;
  14.             int k = 0;
  15.             int d = 0;
  16.             while (t == 1)
  17.             {
  18.                 i = 0;
  19.                 r = -1;
  20.                 k = 0;
  21.                 while (i < c.Length)
  22.                 {
  23.                     k = 0;
  24.                     for (int f = i; f < c.Length; f++)
  25.                     {
  26.                         if (c[f] == ' ')
  27.                         {
  28.                             d = f;
  29.                             break;
  30.                         }
  31.                         else
  32.                         {
  33.                             r++;
  34.                             i++;
  35.                         }
  36.                     }
  37.                     if (r % 2 == 0)
  38.                     {
  39.                         for (int f = i - r - 1; f <(i-r-1)+r/2; f++)
  40.                         {
  41.                             string j = Char.ToString(c[f]);
  42.                             v = c.Remove(f, 1);
  43.                             c = v.Insert(f, Char.ToString(c[f + r - k]));
  44.                             v = c.Remove(f + r - k, 1);
  45.                             c = v.Insert(f + r - k, j);
  46.                             k += 2;
  47.                         }
  48.                     }
  49.                     else
  50.                     {
  51.                         for (int f = i - r - 1; f <(i-r-1)+(r/ 2 + 0.5); f++)
  52.                         {
  53.                             string j = Char.ToString(c[f]);
  54.                             v = c.Remove(f, 1);
  55.                             c = v.Insert(f, Char.ToString(c[f + r - k]));
  56.                             v = c.Remove(f + r - k, 1);
  57.                             c = v.Insert(f + r - k, j);
  58.                             k += 2;
  59.                         }
  60.                     }
  61.                     r = -1;
  62.                     if (i < (c.Length-1))
  63.                     {
  64.                         i=d;
  65.                         i++;
  66.                     }
  67.                 }
  68.                 Console.WriteLine("ИТОГ: ");
  69.                 Console.WriteLine();
  70.                 Console.WriteLine(c);
  71.                 Console.WriteLine();
  72.                 Console.WriteLine("Совершить обратную операцию?");
  73.                 Console.WriteLine("1.Да 2.Нет");
  74.                 t = int.Parse(Console.ReadLine());
  75.                 if (t > 2 || t < 1)
  76.                 {
  77.                     while (t > 2 || t < 1)
  78.                     {
  79.                         Console.WriteLine("Таких вариантов нет. Либо 1, либо 2");
  80.                         t = int.Parse(Console.ReadLine());
  81.                     }
  82.                 }
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement