Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string ANDOperation(int a, int b) {
- if (a == 1 && b == 1) {
- return "1";
- }
- return "0";
- }
- string OROperation(int a, int b) {
- if (a == 0 && b == 0) {
- return "0";
- }
- return "1";
- }
- string NOTOperation(int n) {
- if (n == 0) {
- return "1";
- }
- return "0";
- }
- int main() {
- string str, strTwo = "";
- cin >> str;
- int x = 0, k = 8, n = 8;
- string a = "", b = "", c = "";
- while (true) {
- char ch = str[x];
- if (ch == '+') {
- x++;
- continue;
- }
- if (x == str.length()) {
- break;
- }
- strTwo = "";
- bool flag = true;
- int count = 0;
- for (int i = 0; i < n; i++) {
- if (flag) {
- strTwo += "0";
- count++;
- if (count == (k / 2)) {
- flag = false;
- count = 0;
- }
- } else {
- strTwo += "1";
- count++;
- if (count == (k / 2)) {
- count = 0;
- flag = true;
- }
- }
- }
- k /= 2;
- if (x == 0) {
- a += strTwo;
- } else if (x == 1) {
- b += strTwo;
- } else if (x == 3) {
- c += strTwo;
- }
- x++;
- }
- strTwo = "";
- for (int i = 0; i < c.size(); i++) {
- strTwo += NOTOperation((c[i] - '0'));
- }
- c = strTwo;
- string AB = "", ans = "";
- for (int i = 0; i < a.size(); i++) {
- AB += ANDOperation((a[i] - '0'), (b[i] - '0'));
- }
- for (int i = 0; i < AB.size(); i++) {
- ans += OROperation((AB[i] - '0'), (c[i] - '0'));
- }
- cout << "A\tB\tc'\t" << str << endl;
- for (int i = 0; i < a.size(); i++) {
- cout << a[i] << "\t" << b[i] << "\t" << c[i] << "\t" << ans[i] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement