标签:style blog color io for div sp log on
一个数组中除开唯一一个元素只出现一次,其余的元素均出现三次。
位运算,看不明白,留着以后看吧。
1 #include <stdio.h> 2 #include <algorithm> 3 using namespace std; 4 #define maxn 1000 5 int a[maxn],n; 6 7 int main() 8 { 9 while(scanf("%d",&n), n) 10 { 11 int one = 0, two = 0, three = 0; 12 for(int i=0; i<n; i++) 13 { 14 scanf("%d",&a[i]); 15 three = two & a[i]; 16 two = two | one & a[i]; 17 one = one | a[i]; 18 two = two & ~three; 19 one = one & ~three; 20 } 21 printf("%d\n",one); 22 } 23 return 0; 24 }
标签:style blog color io for div sp log on
原文地址:http://www.cnblogs.com/catdrivedragon/p/3972070.html