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

来源:互联网 发布:c语言buffer 编辑:程序博客网 时间:2024/05/19 19:59

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; }
0 0
原创粉丝点击