转载:http://www.cnblogs.com/siuginhung/p/7743536.html
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#define LL long long
#define maxn 5005
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int num;
char ch;
int x,y;
x=0;y=1023;
for(int i=0;i<n;i++)
{
cin>>ch>>num;
if(ch=='|')
{
x|=num;
y|=num;
}
else if(ch=='^')
{
x^=num;
y^=num;
}
else if(ch=='&')
{
x&=num;
y&=num;
}
}
int and_,or_,xor_;
and_=or_=xor_=0;
int bit;
for(int i=0;i<10;i++)
{
bit=1<<i;
if(x&bit)
{
if(y&bit)
{
or_|=bit;
}
else
xor_|=bit;
and_|=bit;
}
else
{
if(y&bit)
and_|=bit;
}
}
cout << 3 << endl;
cout << '&' << ' ' << and_ << endl;
cout << '|' << ' ' << or_ << endl;
cout << '^' << ' ' << xor_ << endl;
}
return 0;
}