hdu 2568

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2568

题意:中文。

mark:看清楚题就好了。就是求二进制表示时1的个数。本来嘛递归直接可以搞,请容我装逼一下用了位运算。。。

代码:

 1 # include <stdio.h>
 2 
 3 
 4 int calc(int x){return x?calc(x-(x&-x))+1:0;}
 5 
 6 
 7 int main ()
 8 {
 9     int T, n ;
10     scanf ("%d", &T) ;
11     while(T--)
12     {
13         scanf ("%d", &n) ;
14         printf ("%d\n", calc(n)) ;
15     }
16     return 0 ;
17 }
posted @ 2012-04-27 05:33  Seraph2012  阅读(153)  评论(0编辑  收藏  举报