标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 799 Accepted Submission(s): 492
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include <queue> using namespace std; int main() { int tcase; scanf("%d",&tcase); while(tcase--){ int n; scanf("%d",&n); int a[100]; int id=0; while(n){ a[id++] = n%2; n/=2; } int k=0,flag=0; for(int i=0;i<id;i++){ if(a[i]!=0) flag = true; if(flag) a[k++] = a[i]; } int ans = 0; for(int i=k-1;i>=0;i--){ int temp = 1; for(int j=0;j<k-1-i;j++) temp*=2; ans+=temp*a[i]; } printf("%d\n",ans); } }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5668231.html