Advertisement
mlmisha

8.9.9

Apr 28th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using System;
  2. public class texto
  3. {
  4.     public string let;
  5.     public int nlet;
  6.     public int sh;
  7.     public texto(string a, int b, int c)
  8.     {
  9.         let = a;
  10.         nlet = b;
  11.         sh = c;
  12.     }
  13. }
  14. class Test
  15. {
  16.     public static void Main()
  17.     {
  18.         Console.WriteLine("Введите текст");
  19.         string c = Console.ReadLine();
  20.         int g = c.Length;
  21.         for (int i = 0; i < c.Length; i++)
  22.         {
  23.             if (c[i] == ' '||c[i]==','||c[i]=='.')
  24.             {
  25.                 g--;
  26.             }
  27.         }
  28.         string v = c;
  29.         c = v.ToLower();
  30.         Console.WriteLine("В тексте {0} букв", g);
  31.         texto[] m = new texto[g-1];
  32.         int y = 0;
  33.         int prov = 0;
  34.         double s = 0;
  35.         for (int i = 1; i <c.Length; i++)
  36.         {
  37.             prov = 0;
  38.             if (c[i] != ' ' && c[i] != ',' && c[i] != '.'&& c[i-1] != ' ' && c[i-1] != ',' && c[i-1] != '.')
  39.             {
  40.                 if (y > 0)
  41.                 {
  42.                     for (int t = 0; t <= y - 1; t++)
  43.                     {
  44.                         if (String.Concat(c[i - 1], c[i]) == m[t].let)
  45.                         {
  46.                             m[t].nlet++;
  47.                             prov++;
  48.                             s++;
  49.                         }
  50.                     }
  51.                 }
  52.                 if (prov == 0)
  53.                 {
  54.                     int f = 0;
  55.                     int a = 3;
  56.                     m[y] = new texto(String.Concat(c[i - 1], c[i]), 1, y);
  57.                     while (f < c.Length)
  58.                     {
  59.                         if (c[f] == m[y].sh)
  60.                         {
  61.                             f = 0;
  62.                             m[y].sh = y + a;
  63.                             a++;
  64.                         }
  65.                         f++;
  66.                     }
  67.                     if (i < c.Length - 1)
  68.                     {
  69.                         y++;
  70.                     }
  71.                     s++;
  72.                 }
  73.             }
  74.         }
  75.         s = s / y;
  76.         string v = c;
  77.         Console.WriteLine();
  78.         Console.WriteLine("Шифры");
  79.         Console.WriteLine();
  80.         int r = 0;
  81.         for (int i = 0; i < y; i++)
  82.         {
  83.             if (m[i].nlet > s)
  84.             {
  85.                 if (r % 2 == 0)
  86.                 {
  87.                     v = c.Replace(m[i].let, m[i].sh.ToString());
  88.                     Console.WriteLine("Шифр {0} -> '{1}'", m[i].sh, m[i].let);
  89.                     r++;
  90.                 }
  91.                 else
  92.                 {
  93.                     c = v.Replace(m[i].let, m[i].sh.ToString());
  94.                     Console.WriteLine("Шифр {0} -> '{1}'", m[i].sh, m[i].let);
  95.                     r++;
  96.                 }
  97.             }
  98.         }
  99.         if (r > 0)
  100.         {
  101.             Console.WriteLine();
  102.             Console.WriteLine("Итоговый текст");
  103.             if (r % 2 == 0)
  104.             {
  105.                 Console.WriteLine(c);
  106.             }
  107.             else
  108.             {
  109.                 Console.WriteLine(v);
  110.             }
  111.         }
  112.         else
  113.         {
  114.             Console.WriteLine("Повторяющихся комбинаций нет");
  115.         }
  116.  
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement