您的位置:首页 > 其它

2568:前进

2015-09-18 15:53 134 查看
题目链接: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;
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: