题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5142
解题思路:
这个题直接模拟就行,把数表示成二进制,然后翻转一下,再倒着算出来,就行了
AC代码:
#include <iostream> #include <cstdio> using namespace std; int main(){ int n,T; scanf("%d",&T); while(T--){ int i = 0,sum = 0,a[35]; scanf("%d",&n); while(n){ a[i++] = n%2; n /= 2; //cout<<a[i-1]<<endl; } int p = 1; for(int j = i-1; j >= 0; j--){ sum += a[j]*p; //cout<<sum<<endl; p *= 2; } printf("%d\n",sum); } return 0; }