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];
}

#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];
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Defunct SpaceX rocket crashes into Moon at 8,690km/h

In a dramatic climax to a multi-year journey through space, a rogue SpaceX rocket stage has slammed into the far side of the Moon...

7 Reasons This Reusable Food Storage Bags Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

LoanDepot Q2 Revenue Jumps 18% on Home Equity Expansion

Mortgage lender LoanDepot has reported a strong financial turnaround for the second quarter, largely fueled by its aggressive and strategic expansion into home equity...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!