3 4 6 7
1 2 3
二进制数中1的个数!
AC码:
#include<stdio.h> int main() { int T,n,s; scanf("%d",&T); while(T--) { scanf("%d",&n); s=0; while(n) { n=n&(n-1); s++; } printf("%d\n",s); } return 0; }
AC码:
#include<stdio.h> int main() { int T,n,sum; scanf("%d",&T); while(T--) { scanf("%d",&n); sum=0; while(n) { sum+=n%2; n=n/2; } printf("%d\n",sum); } return 0; }
原文地址:http://blog.csdn.net/u012804490/article/details/24778049