http://acm.hdu.edu.cn/showproblem.php?pid=1390
题目是进制转化的问题,难的在于题目读不懂The positions of 1's in the binary representation of 13 are 0, 2, 3.这句,是说1在13的二进制数中的位置是0.2.3
View Code
1 #include<stdio.h> 2 int main() 3 { 4 int n,d,i,j,first; 5 int a[10000]; 6 scanf("%d",&d); 7 while(d--) 8 { 9 scanf("%d",&n); 10 i=0; 11 first=0; 12 while(n) 13 { 14 a[i++]=n%2; 15 n/=2; 16 } 17 for(j=0;j<i;j++) 18 { 19 if(a[j]==1) 20 { 21 if(first==0) 22 printf("%d",j); 23 else printf(" %d",j); 24 first=1; 25 } 26 } 27 printf("\n"); 28 } 29 return 0; 30 }