码迷,mamicode.com
首页 > 其他好文 > 详细

找出重复次数不同的数

时间:2018-03-17 19:45:06      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:com   mes   个数   +=   names   include   for   cstring   stream   

技术分享图片

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int bit[32];/*储存n个数1 - 32位1的个数*/
 6 int value, n;
 7 int main()
 8 {
 9     while (~scanf("%d", &n)) {
10         memset(bit, 0, sizeof(bit));
11         for (int i = 0; i < n; ++i) {
12             scanf("%d", &value);
13             for (int i = 0; i < 32; ++i) {
14                 bit[i] += (value >>i) & 1;
15             }
16         }
17         value = 0;
18         for (int i = 0; i < 32; ++i) {
19             value |= (bit[i] % 3) <<i;/*这里的%3是重点, 因为出了特殊的那个数,其他数1的个数必定是3的倍数,%3就是得到特殊数的第i位*/
20         }
21         printf("%d\n", value);
22     }
23 }

 

找出重复次数不同的数

标签:com   mes   个数   +=   names   include   for   cstring   stream   

原文地址:https://www.cnblogs.com/zfdyf/p/jisuanke_dandudeshuzi.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!