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;
- vector<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.push_back(strTwo);
- } else if (x == 1) {
- b.push_back(strTwo);
- } else if (x == 3) {
- c.push_back(strTwo);
- }
- x++;
- }
- strTwo = "";
- for (int i = 0; i < c[0].size(); i++) {
- strTwo += NOTOperation((c[0][i] - '0'));
- }
- c[0] = strTwo;
- string AB = "", ans = "";
- for (int i = 0; i < a[0].size(); i++) {
- AB += ANDOperation((a[0][i] - '0'), (b[0][i] - '0'));
- }
- for (int i = 0; i < AB.size(); i++) {
- ans += OROperation((AB[i] - '0'), (c[0][i] - '0'));
- }
- cout << "A\tB\tc'\t" << str << endl;
- for (int i = 0; i < a[0].size(); i++) {
- cout << a[0][i] << "\t" << b[0][i] << "\t" << c[0][i] << "\t" << ans[i] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement