&
)|
)~
)^
)<<
, >>
)&
)0 | 1 | |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
int a = 0x0000000F;
a &= 0x0000000A; // a = a & 0x0000000A
printf("%d\n", a);
darkknive@1091cp1:~$ gcc ./main.c
darkknive@1091cp1:~$ ./a.out
10
darkknive@1091cp1:~$
F | 1 | 1 | 1 | 1 |
A | 1 | 0 | 1 | 0 |
results | 1 | 0 | 1 | 0 |
|
)0 | 1 | |
---|---|---|
0 | 0 | 1 |
1 | 1 | 1 |
int a = 0x00000006;
a |= 0x0000000A; // a = a | 0x0000000A;
printf("%d\n", a);
darkknive@1091cp1:~$ gcc ./main.c
darkknive@1091cp1:~$ ./a.out
14
darkknive@1091cp1:~$
6 | 0 | 1 | 1 | 0 |
A | 1 | 0 | 1 | 0 |
results | 1 | 1 | 1 | 0 |
~
)0 | 1 | |
---|---|---|
~ | 1 | 0 |
int a = 0xFFFFFFFA;
a = ~a;
printf("%d\n", a);
darkknive@1091cp1:~$ gcc ./main.c
darkknive@1091cp1:~$ ./a.out
5
darkknive@1091cp1:~$
F | 1 | 1 | 1 | 1 |
results | 0 | 0 | 0 | 0 |
A | 1 | 0 | 1 | 0 |
results | 0 | 1 | 0 | 1 |
^
)0 | 1 | |
---|---|---|
0 | 0 | 1 |
1 | 1 | 0 |
int a = 0x00000006;
a ^= 0x0000000A; // a = a ^ 0x0000000A;
printf("%d\n", a);
darkknive@1091cp1:~$ gcc ./main.c
darkknive@1091cp1:~$ ./a.out
12
darkknive@1091cp1:~$
6 | 0 | 1 | 1 | 0 |
A | 1 | 0 | 1 | 0 |
results | 1 | 1 | 0 | 0 |
<<
, >>
)int a = 0x000000F1;
a >>= 2; // a = a >> 2;
printf("%d\n", a);
a <<= 2; // a = a << 2;
printf("%d\n", a);
darkknive@1091cp1:~$ gcc ./main.c
darkknive@1091cp1:~$ ./a.out
60
240
darkknive@1091cp1:~$
0xF1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
>>=2 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
0x3C | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
<<=2 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
A list of numbers is given, and every number appears twice except one. Please find out which one is it.
Put every number into a list, sort and find which number only appears once.
Time complexity: O(NlogN)
Start with 0, and do XOR operation with each number read.
Time complexity: O(N)
int a = 0;
int tmp;
while(scanf("%d", &tmp) != EOF){
a ^= tmp;
}
printf("%d\n", a);