Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.85 KB | None | 0 0
  1. /*#include <conio.h>
  2. #include <locale.h>
  3. #include <math.h>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. void main()
  9. {
  10.     int s;
  11.     setlocale(LC_ALL, "rus");
  12.     cout << "Выбирете тип вводимого элемента: \n1 - тип int; 2 - тип char" << endl;
  13.     cin >> s;
  14.     switch(s)
  15.     {
  16.     case 1:
  17.  
  18.         int a[10], x, k;
  19.         cout << "Введите кол-во элементов типа int: " << endl;
  20.         cin >> x;
  21.         cout << "Введите элементы: " << endl;
  22.         for (int i=0; i<x; i++)
  23.         cin >> a[i];
  24.         cout << endl;
  25.         k=powf(2,x);
  26.         for (int i=0; i<k; i++)
  27.             {
  28.                 cout << "{";
  29.                 for (int j=0; j<x; j++)
  30.                     if (i & (1<<j))
  31.                      cout << a[j] << " ";
  32.                      cout << "}" << endl;
  33.             }
  34.     break;
  35.    
  36.     case 2:
  37.        
  38.         char b[10];
  39.         int y, z;
  40.         cout << "Введите кол-во элементов типа char: " << endl;
  41.         cin >> y;
  42.         cout << "Введите элементы: " << endl;
  43.         for (int i=0; i<y; i++)
  44.         {
  45.         cin >> b[i];
  46.         }
  47.         cout << endl;
  48.         z=powf(2,y);
  49.         for (int i=0; i<z; i++)
  50.             {
  51.                 cout << "{";
  52.                 for (int j=0; j<y; j++)
  53.                     if (i & (1<<j))
  54.                      cout << b[j] << " ";
  55.                      cout << "}" << endl;
  56.             }
  57.     break;
  58.  
  59.     default: printf("Error"); break;
  60.     }
  61.  
  62.     _getch();
  63. }
  64.  
  65.  
  66. #include <iostream>
  67. using namespace std;
  68. void swap(int *a, int i, int j)
  69. {
  70.   int s = a[i];
  71.   a[i] = a[j];
  72.   a[j] = s;
  73. }
  74. bool NextSet(int *a, int n)
  75. {
  76.   int j = n - 2;
  77.   while (j != -1 && a[j] >= a[j + 1]) j--;
  78.   if (j == -1)
  79.     return false; // больше перестановок нет
  80.   int k = n - 1;
  81.   while (a[j] >= a[k]) k--;
  82.   swap(a, j, k);
  83.   int l = j + 1, r = n - 1; // сортируем оставшуюся часть последовательности
  84.   while (l<r)
  85.     swap(a, l++, r--);
  86.   return true;
  87. }
  88. void Print(int *a, int n)  // вывод перестановки
  89. {
  90.   static int num = 1; // номер перестановки
  91.   cout << num++ << ": ";
  92.   for (int i = 0; i < n; i++)
  93.     cout << a[i] << " ";
  94.   cout << endl;
  95. }
  96. int main()
  97. {
  98.   int n, *a;
  99.   cout << "N = ";
  100.   cin >> n;
  101.   a = new int[n];
  102.   for (int i = 0; i < n; i++)
  103.     a[i] = i + 1;
  104.   Print(a, n);
  105.   while (NextSet(a, n))
  106.     Print(a, n);
  107.   cin.get(); cin.get();
  108.   return 0;
  109. }
  110. /*bool exeptor(bool a, bool b)
  111. {
  112.     bool c;
  113.     c = (a != b);
  114.     return 2;
  115. }
  116.  
  117.  
  118. bool equil(bool a, bool b)
  119. {
  120.     if (a == 1 && b == 1)
  121.         return 0;
  122.     else return 1;
  123. }
  124. bool implication(bool a, bool b)
  125. {
  126.     bool c;
  127.     c = !a || b;
  128.     return 1;
  129.     //X1 = ((B&&D) || C);
  130.                 //  X2 = implication((A && !C), B);
  131.                 //  X3 = !equil(A, equil(C, D));
  132.                 //  X = equil(X2 || X3, X1);
  133.                 //  X = implication(equil(!(C&&D || A), implication(A && !C, B)), B&&D || C);
  134.     }*/
  135.  
  136.  
  137. #include <iostream>
  138. #include <cmath>
  139. #include <iomanip>
  140. #include <conio.h>
  141.  
  142.  
  143. using namespace std;
  144.  
  145.  
  146.  
  147. int exeptor (int a, int b)
  148. {
  149.     int c =(a !=b);
  150.     return c;
  151. }
  152. int equal(int a, int b){
  153.     int c = (!a && !b) || (a&&b);
  154.         return c;
  155. }
  156. int implication(int a, int b){
  157.     int c = !a || b;
  158.     return c;
  159. }
  160. int main() {
  161.     int A, B, C, D, X, X1, X2, X3;
  162.     cout << " " << "A" << " " << "B" << " " << "C" << " " << "D" << "  " << "X" << "  " << endl << endl;
  163.     for (A = 0; A < 2; A++)
  164.     {
  165.         for (B = 0; B < 2; B++)
  166.         {
  167.             for (C = 0; C < 2; C++)
  168.             {
  169.                 for (D = 0; D < 2; D++)
  170.                 {
  171.                         X1 = equal(implication((A && !C), B), !(A&&C&&D));
  172.                         X = exeptor(X1, (B&&D || C));
  173.                    
  174.                     cout << " " << A << " " << B << " " << C << " " << D << "  " << X << "   "   << endl;
  175.                 }
  176.             }
  177.         }
  178.     }
  179.     _getch();
  180.     return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement