题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568
方法:模拟过程
思路:大水题,不过挺有意思,重点在于模拟题目所叙述的过程,因为所给的数据量不大,可以用这种方法。
难点:无
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
while(n--)
{
int x;
int num = 0;
cin>>x;
while(x != 0)
{
if(x%2 == 1)
{
x -= 1;
num++;
}
if(x%2 == 0)
x /= 2;
}
cout<<num<<endl;
}
}
}