Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main(string[] args)
  5.     {
  6.         Console.WriteLine("Все кодовые вектора кода Хемминга(7,4) С:");
  7.         int[,] C = new int[7, 16] {
  8.             { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
  9.             { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 },
  10.             { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 },
  11.             { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
  12.             { 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 },
  13.             { 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1 },
  14.             { 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
  15.         };
  16.         for (int i = 0; i < 7; i++) {
  17.             for (int j = 0; j < 16; j++) {
  18.                 Console.Write("{0} ", C[i, j]);
  19.             }
  20.             Console.WriteLine();
  21.         }
  22.  
  23.         string ch = "y";
  24.         while (ch == "y") {
  25.             Console.WriteLine("Введите некодовое слово");
  26.             string w = Console.ReadLine();
  27.             Console.WriteLine("Смежный класс");
  28.             int[,] C1 = summ(w, C);
  29.             for (int i = 0; i < 7; i++) {
  30.                 for (int j = 0; j < 16; j++) {
  31.                     Console.Write("{0}_", C1[i, j]);
  32.                 }
  33.                 Console.WriteLine();
  34.             }
  35.             Console.WriteLine("Лидеры:");
  36.             string[] lid = lider(C1);
  37.             for (int i = 0; i < 16; i++) {
  38.                 Console.WriteLine("{0}_", lid[i]);
  39.  
  40.             }
  41.             Console.WriteLine();
  42.  
  43.             Console.WriteLine("Continu? y/n");
  44.             ch = Console.ReadLine();
  45.         }
  46.  
  47.         Console.ReadKey();
  48.     }
  49.    
  50.     static int[,] summ(string a, int[,]C)
  51.     {
  52.         string str = "";
  53.         int[] a1 = new int[a.Length];
  54.         for (int h = 0; h < a.Length; h++) {
  55.             if (a[h] == '1')
  56.                 a1[h] = 1;
  57.             else
  58.                 a1[h] = 0;
  59.         }
  60.         int[,] a2 = new int[7, 16];
  61.         for (int j = 0; j < 16; j++) {//l=3
  62.             for (int i = 0; i < 7; i++) {//m=7
  63.                 a2[i, j] = a1[i] ^ C[i, j];
  64.  
  65.             }
  66.  
  67.         }
  68.         return a2;
  69.     }
  70.  
  71.     static string[] lider(int[,] a)
  72.     {
  73.         string[] lid = new string[16];
  74.         int k = 0;
  75.         int min = 16;
  76.  
  77.         for (int j = 0; j < 16; j++) {
  78.  
  79.             int kol = 0;
  80.             for (int i = 0; i < 7; i++) {
  81.                 if (a[i, j] == 1) {
  82.                     kol++;
  83.                 }
  84.             }
  85.             if (kol <= min) {
  86.                 min = kol;
  87.             }
  88.  
  89.         }
  90.  
  91.         for (int j = 0; j < 16; j++) {
  92.             string str = "";
  93.             int kol = 0;
  94.             for (int i = 0; i < 7; i++) {
  95.                 if (a[i, j] == 1) {
  96.                     str += '1';
  97.                     kol++;
  98.                 } else
  99.                     str += '0';
  100.             }
  101.             if (kol == min) {
  102.                 lid[k] = str;
  103.                 k++;
  104.             }
  105.  
  106.         }
  107.         return lid;
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement