Advertisement
Guest User

Matlog

a guest
Nov 22nd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3. using namespace std;
  4. const int n = 16;
  5. int main() {
  6.     setlocale(LC_ALL, "Rus");
  7.     bool a[n], b[n], c[n], d[n], rez[n];
  8.     bool pol[n];
  9.     int x = 0, t1, t2, t3, i, k = 0, m = 0;
  10.     int count1 = 0, count = 0, j = 0;
  11.     int temp[10];
  12.     const int p = 3;
  13.     string T0[p], T1[p], tm[p], tl[p], ts[p];
  14.     a[k] = 0; b[k] = 0; c[k] = 0; d[k] = 0;
  15.     for (i = 0; i < p; i++) {
  16.         T0[i] = "-";
  17.         T1[i] = "-";
  18.         tm[i] = "-";
  19.         tl[i] = "-";
  20.         ts[i] = "-";
  21.     }
  22.     //Таблица истинности
  23.         //cout << 'A' << ' ' << 'B' << ' ' << 'C' << ' ' << 'D' << ' ' << 'f' << endl;
  24.     for (int j = 0; j < n - 1; j++) {
  25.         rez[j] = a[k] && d[k] || b[k] && d[k]  ||c[k];
  26.         x++;
  27.         t1 = x;
  28.         for (i = 0; i < 4; i++) {
  29.             temp[i] = 0;
  30.         }
  31.         i = 0;
  32.         if (t1 == 1) temp[0] = 1;
  33.         while (t1 >= 2) {
  34.             m++;
  35.             t2 = t1;
  36.             t1 /= 2;
  37.             t3 = t2 - t1 * 2;
  38.             temp[i] = t3;
  39.             i++;
  40.             temp[i] = 1;
  41.         }
  42.         k++;
  43.         d[k] = temp[0];
  44.         c[k] = temp[1];
  45.         b[k] = temp[2];
  46.         a[k] = temp[3];;
  47.     }
  48.     rez[x] = a[k] && d[k] || b[k] && d[k] || c[k];
  49.     /*for (i = 0; i < n; i++) {
  50.         cout << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << d[i] << ' ' << rez[i];
  51.         cout << endl;
  52.     }
  53.     cout << endl << endl; */
  54.     //T0
  55.     if (rez[0] == 0) T0[0] = "+";
  56.     //T1
  57.     if (rez[n-1] == 1) T1[0] = "+";
  58.     //Монотонность
  59.     for (i = 0; i < n - 1; i++) {
  60.         if (rez[i] > rez[i + 1]) count++;
  61.     }
  62.     if (count == 0) tm[0] = "+";
  63.     //Самодвойственность
  64.     count = 0;
  65.     j = n - 1;
  66.     for (i = 0; i < (n / 2); i++) {
  67.         if (rez[i] == rez[j]) count++;
  68.         j--;
  69.     }
  70.     if (count == 0) ts[0] = "+";
  71.     //Линейность
  72.     i = n;
  73.     pol[0] = 0;
  74.     j = 0;
  75.     for (int m = 0; m < n; m++) {
  76.         while (j != i - 1) {
  77.             if ((rez[j] == 0 && rez[j + 1] == 1) || (rez[j] == 1 && rez[j + 1] == 0)) {
  78.                 rez[j] = 1;
  79.             }
  80.             else rez[j] = 0;
  81.     //      cout << rez[j];
  82.             j++;
  83.         }
  84.     //  cout << endl;
  85.         i--;
  86.         pol[m+1] = rez[0];
  87.         j = 0;
  88.     }
  89.     count = 0;
  90.     for (i = 0; i < n; i++) {
  91.         if (pol[i] == 1) {
  92.             if (a[i] == 1) count1++;
  93.             if (b[i] == 1) count1++;
  94.             if (c[i] == 1) count1++;
  95.             if (d[i] == 1) count1++;
  96.         }
  97.         if (count1 > count) count = count1;
  98.         count1 = 0;
  99.     }
  100. //  cout << count;
  101.     if (count <= 1) tl[0] = "+";
  102. //  cout << endl;
  103.     //Вывод итоговых значений
  104. /*  cout << T0 << ' ' << T1 << ' ' << tm << ' ' << tl << ' ' << ts;
  105.     cout << endl;
  106.     if (T0 == "-" && T1 == "-" && tm == "-" && ts == "-" && tl == "-") cout << "Функционально полная";
  107.     else cout << "Функционально не полная";
  108.     cout << endl << endl; */
  109.    
  110.     x = 0; k = 0; m = 0;
  111.     count1 = 0; count = 0; j = 0;
  112.     x = 0;
  113. //  cout << 'A' << ' ' << 'B' << ' ' << 'C' << ' ' << 'D' << ' ' << 'f' << endl;
  114.     for (int j = 0; j < n - 1; j++) {
  115.         rez[j] = a[k] && b[k] && !c[k] || !b[k] && c[k] && d[k] || !a[k] && d[k];
  116.         x++;
  117.         t1 = x;
  118.         for (i = 0; i < 4; i++) {
  119.             temp[i] = 0;
  120.         }
  121.         i = 0;
  122.         if (t1 == 1) temp[0] = 1;
  123.         while (t1 >= 2) {
  124.             m++;
  125.             t2 = t1;
  126.             t1 /= 2;
  127.             t3 = t2 - t1 * 2;
  128.             temp[i] = t3;
  129.             i++;
  130.             temp[i] = 1;
  131.         }
  132.         k++;
  133.         d[k] = temp[0];
  134.         c[k] = temp[1];
  135.         b[k] = temp[2];
  136.         a[k] = temp[3];;
  137.     }
  138.     rez[x] = a[k] && b[k] && !c[k] || !b[k] && c[k] && d[k] || !a[k] && d[k];
  139.     /*for (i = 0; i < n; i++) {
  140.         cout << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << d[i] << ' ' << rez[i];
  141.         cout << endl;
  142.     }
  143.     cout << endl << endl;*/
  144.     //T0
  145.     if (rez[0] == 0) T0[1] = "+";
  146.     //T1
  147.     if (rez[n - 1] == 1) T1[1] = "+";
  148.     //Монотонность
  149.     for (i = 0; i < n - 1; i++) {
  150.         if (rez[i] > rez[i + 1]) count++;
  151.     }
  152.     if (count == 0) tm[1] = "+";
  153.     //Самодвойственность
  154.     count = 0;
  155.     j = n - 1;
  156.     for (i = 0; i < (n / 2); i++) {
  157.         if (rez[i] == rez[j]) count++;
  158.         j--;
  159.     }
  160.     if (count == 0) ts[1] = "+";
  161.     //Линейность
  162.     i = n;
  163.     pol[0] = 0;
  164.     j = 0;
  165.     for (int m = 0; m < n; m++) {
  166.         while (j != i - 1) {
  167.             if ((rez[j] == 0 && rez[j + 1] == 1) || (rez[j] == 1 && rez[j + 1] == 0)) {
  168.                 rez[j] = 1;
  169.             }
  170.             else rez[j] = 0;
  171.         //  cout << rez[j];
  172.             j++;
  173.         }
  174.     //  cout << endl;
  175.         i--;
  176.         pol[m + 1] = rez[0];
  177.         j = 0;
  178.     }
  179.     count = 0;
  180.     for (i = 0; i < n; i++) {
  181.         if (pol[i] == 1) {
  182.             if (a[i] == 1) count1++;
  183.             if (b[i] == 1) count1++;
  184.             if (c[i] == 1) count1++;
  185.             if (d[i] == 1) count1++;
  186.         }
  187.         if (count1 > count) count = count1;
  188.         count1 = 0;
  189.     }
  190.     //cout << count;
  191.     if (count <= 1) tl[1] = "+";
  192.     //cout << endl;
  193.     //Вывод итоговых значений
  194.     /*cout << T0 << ' ' << T1 << ' ' << tm << ' ' << tl << ' ' << ts;
  195.     cout << endl;
  196.     if (T0 == "-" && T1 == "-" && tm == "-" && ts == "-" && tl == "-") cout << "Функционально полная";
  197.     else cout << "Функционально не полная";
  198.     cout << endl;*/
  199.  
  200.  
  201.     x = 0; k = 0; m = 0;
  202.     count1 = 0; count = 0; j = 0;
  203.     x = 0;
  204.     //  cout << 'A' << ' ' << 'B' << ' ' << 'C' << ' ' << 'D' << ' ' << 'f' << endl;
  205.     for (int j = 0; j < n - 1; j++) {
  206.         rez[j] = (a[k] || !b[k] || !c[k]) && (b[k] || c[k] || !d[k]) && (!b[k] || !d[k]);
  207.         x++;
  208.         t1 = x;
  209.         for (i = 0; i < 4; i++) {
  210.             temp[i] = 0;
  211.         }
  212.         i = 0;
  213.         if (t1 == 1) temp[0] = 1;
  214.         while (t1 >= 2) {
  215.             m++;
  216.             t2 = t1;
  217.             t1 /= 2;
  218.             t3 = t2 - t1 * 2;
  219.             temp[i] = t3;
  220.             i++;
  221.             temp[i] = 1;
  222.         }
  223.         k++;
  224.         d[k] = temp[0];
  225.         c[k] = temp[1];
  226.         b[k] = temp[2];
  227.         a[k] = temp[3];;
  228.     }
  229.     rez[x] = (a[k] || !b[k] || !c[k]) && (b[k] || c[k] || !d[k]) && (!b[k] || !d[k]);
  230.     /*for (i = 0; i < n; i++) {
  231.         cout << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << d[i] << ' ' << rez[i];
  232.         cout << endl;
  233.     }
  234.     cout << endl << endl;*/
  235.     //T0
  236.     if (rez[0] == 0) T0[2] = "+";
  237.     //T1
  238.     if (rez[n - 1] == 1) T1[2] = "+";
  239.     //Монотонность
  240.     for (i = 0; i < n - 1; i++) {
  241.         if (rez[i] > rez[i + 1]) count++;
  242.     }
  243.     if (count == 0) tm[2] = "+";
  244.     //Самодвойственность
  245.     count = 0;
  246.     j = n - 1;
  247.     for (i = 0; i < (n / 2); i++) {
  248.         if (rez[i] == rez[j]) count++;
  249.         j--;
  250.     }
  251.     if (count == 0) ts[2] = "+";
  252.     //Линейность
  253.     i = n;
  254.     pol[0] = 0;
  255.     j = 0;
  256.     for (int m = 0; m < n; m++) {
  257.         while (j != i - 1) {
  258.             if ((rez[j] == 0 && rez[j + 1] == 1) || (rez[j] == 1 && rez[j + 1] == 0)) {
  259.                 rez[j] = 1;
  260.             }
  261.             else rez[j] = 0;
  262.             //  cout << rez[j];
  263.             j++;
  264.         }
  265.         //  cout << endl;
  266.         i--;
  267.         pol[m + 1] = rez[0];
  268.         j = 0;
  269.     }
  270.     count = 0;
  271.     for (i = 0; i < n; i++) {
  272.         if (pol[i] == 1) {
  273.             if (a[i] == 1) count1++;
  274.             if (b[i] == 1) count1++;
  275.             if (c[i] == 1) count1++;
  276.             if (d[i] == 1) count1++;
  277.         }
  278.         if (count1 > count) count = count1;
  279.         count1 = 0;
  280.     }
  281.     //cout << count;
  282.     if (count <= 1) tl[2] = "+";
  283. //  cout << endl;
  284.     //Вывод итоговых значений
  285.     /*cout << T0 << ' ' << T1 << ' ' << tm << ' ' << tl << ' ' << ts;
  286.     cout << endl;
  287.     if (T0 == "-" && T1 == "-" && tm == "-" && ts == "-" && tl == "-") cout << "Функционально полная";
  288.     else cout << "Функционально не полная";
  289.     cout << endl;*/
  290.     int countT0=0, countT1=0, counttm=0, counttl=0, countts=0;
  291.     for (i = 0; i < p; i++) {
  292.         cout << T0[i];
  293.         if (T0[i] == "-") countT0++;
  294.         cout << T1[i];
  295.         if (T1[i] == "-") countT1++;
  296.         cout << tm[i];
  297.         if (tm[i] == "-") counttm++;
  298.         cout << tl[i];
  299.         if (tl[i] == "-") counttl++;
  300.         cout << ts[i] << endl;
  301.         if (ts[i] == "-") countts++;
  302.     }
  303.     if (countT0 >= 1 && countT1 >= 1 && counttm >= 1 && counttl >= 1 && countts >= 1)
  304.         cout << "система функциональна полная";
  305.     else cout << "система функционально не полная";
  306.  
  307.     cout << endl;
  308.     system("pause");
  309.     return 0;
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement