日常补题2017-10-31

 

A. Short Program

很巧妙的处理方式,用0和1023来记录

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main(){
 5     int n;
 6     scanf("%d", &n);
 7     char s[3];
 8     int op;
 9     int a = 0, b = 1023;
10     for(int i = 0; i < n; i++){
11         scanf("%s %d", s, &op);
12         if(s[0] == '|') a |= op, b |= op;
13         if(s[0] == '&') a &= op, b &= op;
14         if(s[0] == '^') a ^= op, b ^= op;
15     }
16     int u = 0, v = 0;
17     for(int i = 0; i < 10; i++){
18         int x = 1<<i;
19         if(a&x && b&x) u |= x;
20         if(a&x && ~b&x) v |= x;
21         if(~a&x && ~b&x) u |= x, v |= x;
22     }
23     printf("2\n| %d\n^ %d\n",u, v);
24 }
View Code

 

posted @ 2017-10-31 22:58  yijiull  阅读(109)  评论(0编辑  收藏  举报