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

国防科大校赛决赛-final(镜像赛) Problem B: XueXX and Binary

2016-05-15 17:43 423 查看
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 cases T (T<=100). The descriptions of the test cases follow: The first line of each test case contains one integer a (0

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,ans=0;
cin>>n;
while(n)
{
n&=n-1;
ans++;
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: