Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Все кодовые вектора кода Хемминга(7,4) С:");
- int[,] C = new int[7, 16] {
- { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
- { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 },
- { 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 },
- { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
- { 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 },
- { 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1 },
- { 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
- };
- for (int i = 0; i < 7; i++) {
- for (int j = 0; j < 16; j++) {
- Console.Write("{0} ", C[i, j]);
- }
- Console.WriteLine();
- }
- string ch = "y";
- while (ch == "y") {
- Console.WriteLine("Введите некодовое слово");
- string w = Console.ReadLine();
- Console.WriteLine("Смежный класс");
- int[,] C1 = summ(w, C);
- for (int i = 0; i < 7; i++) {
- for (int j = 0; j < 16; j++) {
- Console.Write("{0}_", C1[i, j]);
- }
- Console.WriteLine();
- }
- Console.WriteLine("Лидеры:");
- string[] lid = lider(C1);
- for (int i = 0; i < 16; i++) {
- Console.WriteLine("{0}_", lid[i]);
- }
- Console.WriteLine();
- Console.WriteLine("Continu? y/n");
- ch = Console.ReadLine();
- }
- Console.ReadKey();
- }
- static int[,] summ(string a, int[,]C)
- {
- string str = "";
- int[] a1 = new int[a.Length];
- for (int h = 0; h < a.Length; h++) {
- if (a[h] == '1')
- a1[h] = 1;
- else
- a1[h] = 0;
- }
- int[,] a2 = new int[7, 16];
- for (int j = 0; j < 16; j++) {//l=3
- for (int i = 0; i < 7; i++) {//m=7
- a2[i, j] = a1[i] ^ C[i, j];
- }
- }
- return a2;
- }
- static string[] lider(int[,] a)
- {
- string[] lid = new string[16];
- int k = 0;
- int min = 16;
- for (int j = 0; j < 16; j++) {
- int kol = 0;
- for (int i = 0; i < 7; i++) {
- if (a[i, j] == 1) {
- kol++;
- }
- }
- if (kol <= min) {
- min = kol;
- }
- }
- for (int j = 0; j < 16; j++) {
- string str = "";
- int kol = 0;
- for (int i = 0; i < 7; i++) {
- if (a[i, j] == 1) {
- str += '1';
- kol++;
- } else
- str += '0';
- }
- if (kol == min) {
- lid[k] = str;
- k++;
- }
- }
- return lid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement