Advertisement
BMSTU1LOVE

Pizda Na Palke

Dec 16th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<fstream>
  4. #include<cmath>
  5. #include<string>
  6.  
  7. using namespace std;
  8.  
  9. struct Number {                                             // Structure itself
  10.     unsigned int x[7];
  11. };
  12.  
  13. Number operator + (Number a, Number b) {
  14.     Number temp;
  15.     for (int i = 0; i < 7; i++)
  16.         temp.x[i] = 0;
  17.     for (int i = 6; i >= 0; i--) {
  18.         temp.x[i] += a.x[i] + b.x[i];
  19.         if (i != 0) {
  20.             temp.x[i - 1] += (int)temp.x[i] / pow(10, 9);
  21.             temp.x[i] -= temp.x[i - 1] * pow(10, 9);
  22.         }
  23.     }
  24.     return temp;
  25. }
  26.  
  27. Number operator - (Number a, Number b) {
  28.     Number temp;
  29.     for (int i = 0; i < 7; i++)
  30.         temp.x[i] = 0;
  31.     for (int i = 0; i < 7; i++) {
  32.         int k = 0;
  33.         if (a.x[i] >= b.x[i])
  34.             temp.x[i] += a.x[i] - b.x[i];
  35.         else
  36.             if (i != 0) {
  37.                 temp.x[i] += (a.x[i] + pow((int)10, (int)9)) - b.x[i];
  38.                 temp.x[i - 1] -= 1;
  39.             }
  40.     }
  41.     return temp;
  42. }
  43.  
  44. bool operator > (Number a, Number b) {
  45.     bool temp;
  46.     int p = 0,
  47.         n = 0;
  48.     for (int i = 0; i < 7; i++) {
  49.         if (a.x[i] > b.x[i])
  50.             p++;
  51.         else
  52.             if (a.x[i] < b.x[i])
  53.                 n++;
  54.         if (p == 1 && n == 0) {
  55.             temp = true;
  56.             break;
  57.         }
  58.         else
  59.             if (p == 0 && n == 1) {
  60.                 temp = false;
  61.                 break;
  62.             }
  63.             else
  64.                 if (p == 0 && n == 0)
  65.                     temp = false;
  66.     }
  67.     return  temp;
  68. }
  69.  
  70. bool operator < (Number a, Number b) {
  71.     bool temp;
  72.     int p = 0,
  73.         n = 0;
  74.     for (int i = 0; i < 7; i++) {
  75.         if (a.x[i] > b.x[i])
  76.             p++;
  77.         else
  78.             if (a.x[i] < b.x[i])
  79.                 n++;
  80.         if (p == 0 && n == 1) {
  81.             return true;
  82.         }
  83.         else
  84.             if (p == 1 && n == 0) {
  85.                 return false;
  86.             }
  87.             else
  88.                 if (p == 0 && n == 0)
  89.                     temp = false;
  90.     }
  91.     return  temp;
  92. }
  93.  
  94. bool operator == (Number a, Number b) {
  95.     int amount = 0;
  96.     for (int i = 0; i < 7; i++)
  97.         if (a.x[i] == b.x[i])
  98.             amount++;
  99.     if (amount == 7)
  100.         return true;
  101.     else
  102.         return false;
  103. }
  104.  
  105. bool operator != (Number a, Number b) {
  106.     int amount = 0;
  107.     for (int i = 0; i < 7; i++)
  108.         if (a.x[i] == b.x[i])
  109.             amount++;
  110.     if (amount == 7)
  111.         return false;
  112.     else
  113.         return true;
  114. }
  115.  
  116. Number operator & (Number a, Number b) {
  117.     Number temp;
  118.     for (int i = 0; i < 7; i++)
  119.         temp.x[i] = a.x[i] & b.x[i];
  120.     return temp;
  121. }
  122.  
  123. Number operator | (Number a, Number b) {
  124.     Number temp;
  125.     for (int i = 0; i < 7; i++)
  126.         temp.x[i] = a.x[i] | b.x[i];
  127.     return temp;
  128. }
  129.  
  130. Number operator ^ (Number a, Number b) {
  131.     Number temp;
  132.     for (int i = 0; i < 7; i++)
  133.         temp.x[i] = a.x[i] ^ b.x[i];
  134.     return temp;
  135. }
  136.  
  137. Number operator ~ (Number a) {
  138.     for (int i = 0; i < 7; i++)
  139.         a.x[i] = ~a.x[i];
  140.     return a;
  141. }
  142.  
  143. Number operator << (Number a, int x) {
  144.     Number temp;
  145.     for (int i = 0; i < 7; i++)
  146.         temp.x[i] = a.x[i];
  147.     for (int m = 0; m < x; m++) {
  148.         for (int i = 6; i >= 0; i--) {
  149.             temp.x[i] = temp.x[i] << 1;
  150.             if (i != 0)
  151.                 temp.x[i - 1] += temp.x[i] >> 31;
  152.         }
  153.     }
  154.     return temp;
  155. }
  156.  
  157. Number operator <<= (Number a, int x) {
  158.     Number temp;
  159.     for (int i = 0; i < 7; i++)
  160.         temp.x[i] = a.x[i];
  161.     for (int m = 0; m < x; m++) {
  162.         for (int i = 6; i >= 0; i--) {
  163.             temp.x[i] = temp.x[i] << 1;
  164.             if (i != 0)
  165.                 temp.x[i - 1] += temp.x[i] >> 31;
  166.             else
  167.                 temp.x[6] += temp.x[i] >> 31;
  168.         }
  169.     }
  170.     return temp;
  171. }
  172.  
  173. Number operator >> (Number a, int x) {
  174.     Number temp;
  175.     for (int i = 6; i >= 0; i--)
  176.         temp.x[i] = a.x[i];;
  177.     for (int m = 0; m < x; m++) {
  178.         for (int i = 0; i < 7; i++) {
  179.             temp.x[i] = temp.x[i] >> 1;
  180.             if (i != 6)
  181.                 temp.x[i + 1] += temp.x[i] << 31;
  182.         }
  183.     }
  184.     return temp;
  185. }
  186.  
  187. Number operator >>= (Number a, int x) {
  188.     Number temp;
  189.     for (int i = 6; i >= 0; i--)
  190.         temp.x[i] = a.x[i];;
  191.     for (int m = 0; m < x; m++) {
  192.         for (int i = 0; i < 7; i++) {
  193.             temp.x[i] = temp.x[i] >> 1;
  194.             if (i != 6)
  195.                 temp.x[i + 1] += temp.x[i] << 31;
  196.             else
  197.                 temp.x[0] += temp.x[i] << 31;
  198.         }
  199.     }
  200.     return temp;
  201. }
  202.  
  203. void main() {
  204.     Number a[2];
  205.  
  206.     string A[2];                                            // Stuffing STRING with numbers
  207.     for (size_t m = 0; m < 2; m++) {
  208.         cout << "Number " << m + 1 << " = ";
  209.         getline(cin, A[m]);
  210.     }
  211.     int len[2] = { A[0].length(), A[1].length() };
  212.  
  213.     for (size_t m = 0; m < 2; m++)                          // Zeroing STRUCTs
  214.         for (size_t i = 0; i < 7; i++)
  215.             a[m].x[i] = 0;
  216.  
  217.     for (size_t m = 0; m < 2; m++) {                        //Directly stuffing STRUCTs with numbers
  218.         int k1 = 1,
  219.             k2 = 0;
  220.  
  221.         for (int i = len[m] - 1; i >= 0; i--) {
  222.             a[m].x[7 - k1] += ((int)A[m][i] - 48) * pow(10, k2);
  223.             k2++;
  224.             if (k2 == 9) {
  225.                 k1++;
  226.                 k2 = 0;
  227.             }
  228.         }
  229.     }
  230.     cout << endl;
  231.  
  232.     int check;
  233.     for (size_t m = 0; m < 2; m++) {                            // Printing numbers by 9 numerals
  234.         check = 0;
  235.         cout << "Number " << m + 1 << " = ";
  236.         for (size_t i = 0; i < 7; i++) {
  237.             if (a[m].x[i] != 0)
  238.                 check++;
  239.             if (check != 0)
  240.                 if (check != 1)
  241.                     cout << setw(9) << setfill('0') << a[m].x[i] << " ";
  242.                 else
  243.                     cout << a[m].x[i] << " ";
  244.         }
  245.         if (check == 0)
  246.             cout << 0;
  247.         cout << endl;
  248.     }
  249.     cout << endl;
  250.  
  251.     check = 0;
  252.     Number c[2];
  253.     c[0] = a[0] + a[1];                                     // +
  254.     cout << "a + b = ";
  255.     for (size_t i = 0; i < 7; i++) {
  256.         if (c[0].x[i] != 0)
  257.             check++;
  258.         if (check != 0)
  259.             if (check != 1)
  260.                 cout << setw(9) << setfill('0') << c[0].x[i] << " ";
  261.             else
  262.                 cout << c[0].x[i] << " ";
  263.     }
  264.     if (check == 0)
  265.         cout << 0;
  266.     cout << endl;
  267.  
  268.     check = 0;
  269.     c[0] = a[0] - a[1];                                     // -
  270.     cout << "a - b = ";
  271.     for (size_t i = 0; i < 7; i++) {
  272.         if (c[0].x[i] != 0)
  273.             check++;
  274.         if (check != 0)
  275.             if (check != 1)
  276.                 cout << setw(9) << setfill('0') << c[0].x[i] << " ";
  277.             else
  278.                 cout << c[0].x[i] << " ";
  279.     }
  280.     if (check == 0)
  281.         cout << 0;
  282.     cout << endl << endl;
  283.  
  284.     bool C = a[0] > a[1];                                   // >
  285.     if (C == true)
  286.         cout << "a > b : True" << endl;
  287.     else
  288.         cout << "a > b : False" << endl;
  289.  
  290.     C = a[0] < a[1];                                        // <
  291.     if (C == true)
  292.         cout << "a < b : True" << endl;
  293.     else
  294.         cout << "a < b : False" << endl;
  295.  
  296.     C = a[0] == a[1];                                       // ==
  297.     if (C == true)
  298.         cout << "a = b : True" << endl;
  299.     else
  300.         cout << "a = b : False" << endl;
  301.  
  302.     C = a[0] != a[1];                                       // !=
  303.     if (C == true)
  304.         cout << "a != b : True" << endl << endl;
  305.     else
  306.         cout << "a != b : False" << endl << endl;
  307.  
  308.     check = 0;
  309.     c[0] = a[0] & a[1];                                     // &
  310.     cout << "a & b = ";
  311.     for (size_t i = 0; i < 7; i++) {
  312.         if (c[0].x[i] != 0)
  313.             check++;
  314.         if (check != 0)
  315.             if (check != 1)
  316.                 cout << setw(9) << setfill('0') << c[0].x[i] << " ";
  317.             else
  318.                 cout << c[0].x[i] << " ";
  319.     }
  320.     if (check == 0)
  321.         cout << 0;
  322.     cout << endl;
  323.  
  324.     check = 0;
  325.     c[0] = a[0] | a[1];                                     // |
  326.     cout << "a | b = ";
  327.     for (size_t i = 0; i < 7; i++) {
  328.         if (c[0].x[i] != 0)
  329.             check++;
  330.         if (check != 0)
  331.             if (check != 1)
  332.                 cout << setw(9) << setfill('0') << c[0].x[i] << " ";
  333.             else
  334.                 cout << c[0].x[i] << " ";
  335.     }
  336.     if (check == 0)
  337.         cout << 0;
  338.     cout << endl;
  339.  
  340.     check = 0;
  341.     c[0] = a[0] ^ a[1];                                     // ^
  342.     cout << "a ^ b = ";
  343.     for (size_t i = 0; i < 7; i++) {
  344.         if (c[0].x[i] != 0)
  345.             check++;
  346.         if (check != 0)
  347.             if (check != 1)
  348.                 cout << setw(9) << setfill('0') << c[0].x[i] << " ";
  349.             else
  350.                 cout << c[0].x[i] << " ";
  351.     }
  352.     if (check == 0)
  353.         cout << 0;
  354.     cout << endl;
  355.  
  356.     c[0] = ~a[0];                                           // ~
  357.     c[1] = ~a[1];
  358.     for (size_t m = 0; m < 2; m++) {
  359.         if (m == 0)
  360.             cout << "~a = ";
  361.         else
  362.             cout << endl << "~b = ";
  363.         for (size_t i = 0; i < 7; i++)
  364.             if (check != 1)
  365.                 cout << setw(9) << setfill('0') << c[m].x[i] << " ";
  366.             else
  367.                 cout << c[m].x[i] << " ";
  368.     }
  369.     cout << endl << endl;
  370.  
  371.     int amount[2];
  372.     cout << "Amount of shifts <- : ";
  373.     cin >> amount[0] >> amount[1];
  374.  
  375.     c[0] = a[0] << amount[0];                                   // <<
  376.     c[1] = a[1] << amount[1];
  377.     for (size_t m = 0; m < 2; m++) {
  378.         check = 0;
  379.         if (m == 0)
  380.             cout << "a << " << amount[0] << " = ";
  381.         else
  382.             cout << endl << "b << " << amount[1] << " = ";
  383.         for (size_t i = 0; i < 7; i++) {
  384.             if (c[m].x[i] != 0)
  385.                 check++;
  386.             if (check != 0)
  387.                 if (check != 1)
  388.                     cout << setw(9) << setfill('0') << c[m].x[i] << " ";
  389.                 else
  390.                     cout << c[m].x[i] << " ";
  391.         }
  392.         if (check == 0)
  393.             cout << 0;
  394.     }
  395.     cout << endl;
  396.  
  397.     cout << "Amount of shifts -> : ";                           // >>
  398.     cin >> amount[0] >> amount[1];
  399.  
  400.     c[0] = a[0] >> amount[0];
  401.     c[1] = a[1] >> amount[1];
  402.     for (size_t m = 0; m < 2; m++) {
  403.         check = 0;
  404.         if (m == 0)
  405.             cout << "a >> " << amount[0] << " = ";
  406.         else
  407.             cout << endl << "b >> " << amount[1] << " = ";
  408.         for (size_t i = 0; i < 7; i++) {
  409.             if (c[m].x[i] != 0)
  410.                 check++;
  411.             if (check != 0)
  412.                 if (check != 1)
  413.                     cout << setw(9) << setfill('0') << c[m].x[i] << " ";
  414.                 else
  415.                     cout << c[m].x[i] << " ";
  416.         }
  417.         if (check == 0)
  418.             cout << 0;
  419.     }
  420.     cout << endl;
  421.  
  422.     cout << "Amount of CIRCULAR shifts <- : ";                 
  423.     cin >> amount[0] >> amount[1];
  424.  
  425.     c[0] = a[0] <<= amount[0];                                  // <<=
  426.     c[1] = a[1] <<= amount[1];
  427.     for (size_t m = 0; m < 2; m++) {
  428.         check = 0;
  429.         if (m == 0)
  430.             cout << "a <<= " << amount[0] << " = ";
  431.         else
  432.             cout << endl << "b <<= " << amount[1] << " = ";
  433.         for (size_t i = 0; i < 7; i++) {
  434.             if (c[m].x[i] != 0)
  435.                 check++;
  436.             if (check != 0)
  437.                 if (check != 1)
  438.                     cout << setw(9) << setfill('0') << c[m].x[i] << " ";
  439.                 else
  440.                     cout << c[m].x[i] << " ";
  441.         }
  442.         if (check == 0)
  443.             cout << 0;
  444.     }
  445.     cout << endl;
  446.  
  447.     cout << "Amount of CIRCULAR shifts -> : ";                      // >>=
  448.     cin >> amount[0] >> amount[1];
  449.  
  450.     c[0] = a[0] >>= amount[0];
  451.     c[1] = a[1] >>= amount[1];
  452.     for (size_t m = 0; m < 2; m++) {
  453.         check = 0;
  454.         if (m == 0)
  455.             cout << "a >>= " << amount[0] << " = ";
  456.         else
  457.             cout << endl << "b >>= " << amount[1] << " = ";
  458.         for (size_t i = 0; i < 7; i++) {
  459.             if (c[m].x[i] != 0)
  460.                 check++;
  461.             if (check != 0)
  462.                 if (check != 1)
  463.                     cout << setw(9) << setfill('0') << c[m].x[i] << " ";
  464.                 else
  465.                     cout << c[m].x[i] << " ";
  466.         }
  467.         if (check == 0)
  468.             cout << 0;
  469.     }
  470.     cout << endl;
  471.  
  472.     system("pause");
  473. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement