Advertisement
Niloy007

Shohan's Code

Dec 29th, 2020
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string ANDOperation(int a, int b) {
  5.     if (a == 1 && b == 1) {
  6.         return "1";
  7.     }
  8.     return "0";
  9. }
  10.  
  11. string OROperation(int a, int b) {
  12.     if (a == 0 && b == 0) {
  13.         return "0";
  14.     }
  15.     return "1";
  16. }
  17.  
  18. string NOTOperation(int n) {
  19.     if (n == 0) {
  20.         return "1";
  21.     }
  22.     return "0";
  23. }
  24.  
  25. int main() {
  26.     string str, strTwo = "";
  27.     cin >> str;
  28.     int x = 0, k = 8, n = 8;
  29.     string a = "", b = "", c = "";
  30.    
  31.     while (true) {
  32.         char ch = str[x];  
  33.         if (ch == '+') {
  34.             x++;
  35.             continue;
  36.         }
  37.         if (x == str.length()) {
  38.             break;
  39.         }
  40.         strTwo = "";
  41.         bool flag = true;
  42.         int count = 0;
  43.         for (int i = 0; i < n; i++) {  
  44.             if (flag) {
  45.                 strTwo += "0";
  46.                 count++;
  47.                 if (count == (k / 2)) {
  48.                     flag = false;
  49.                     count = 0;
  50.                 }
  51.             } else {
  52.                 strTwo += "1";
  53.                 count++;
  54.                 if (count == (k / 2)) {
  55.                     count = 0;
  56.                     flag = true;
  57.                 }
  58.             }
  59.         }
  60.         k /= 2;
  61.         if (x == 0) {
  62.             a += strTwo;   
  63.         } else if (x == 1) {
  64.             b += strTwo;   
  65.         } else if (x == 3) {
  66.             c += strTwo;   
  67.         }
  68.         x++;
  69.     }
  70.  
  71.     strTwo = "";
  72.     for (int i = 0; i < c.size(); i++) {
  73.         strTwo += NOTOperation((c[i] - '0'));
  74.     }
  75.     c = strTwo;
  76.  
  77.     string AB = "", ans = "";
  78.     for (int i = 0; i < a.size(); i++) {
  79.         AB += ANDOperation((a[i] - '0'), (b[i] - '0'));
  80.     }
  81.  
  82.     for (int i = 0; i < AB.size(); i++) {
  83.         ans += OROperation((AB[i] - '0'), (c[i] - '0'));
  84.     }
  85.  
  86.  
  87.     cout << "A\tB\tc'\t" << str << endl;
  88.     for (int i = 0; i < a.size(); i++) {
  89.         cout << a[i] << "\t" << b[i] << "\t" << c[i] << "\t" << ans[i] << endl;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement