您的位置:首页 > 产品设计 > UI/UE

csuoj-1732-XueXX and Binary

2016-05-27 09:54 363 查看

Description

XueXX is a clever boy. And he always likes numbers in binary(二进制). What an interesting hobby!
Now XueXX has some number in decimal(十进制), he wants to know how many “1”s in a number if the number is written in binary.

Input

The first line of input contains the number of test casesT
(T<=100). The descriptions of the test cases follow: The first line of each test case contains one integera
(0<a<=1,000,000,000), standing for the number in decimal.

Output

For each test case, output a single line containing the result.

Sample Input

3
1
91
735

Sample Output

1
5
8


二进制数1的个数

#include <cstdio>
#include <iostream>
using namespace std;
int n;

int main(){
int T;
scanf("%d", &T);
while (T--){
scanf("%d", &n);
int ans = 0;
while (n){
if (n & 1)
++ans;
n >>= 1;
}
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: