https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/11/Codeforces-Round-443-Div-2-problem-C-Short-Program-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #443 (Div. 2), problem: (C) Short Program Solution In C/C++

#include <iostream>
using namespace std;

const int maxn = 5e5;
int n, x, a = 0, b = 1023, y[3];
char c;

int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> c >> x;
if (c == ‘&’)
{
a &= x;
b &= x;
}
else if (c == ‘|’)
{
a |= x;
b |= x;
}
else
{
a ^= x;
b ^= x;
}
}
for (int i = 0; i < 10; i++)
{
if ((a & (1 << i)) && (b & (1 << i)))
{
y[0] += 1 << i;
y[1] += 1 << i;
}
else if (a & (1 << i))
{
y[0] += 1 << i;
y[2] += 1 << i;
}
else if (b & (1 << i))
{
y[0] += 1 << i;
}
}
cout << 3 << “\n& ” << y[0] << “\n| ” << y[1] << “\n^ ” << y[2];
}

(Visited 4 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: