http://acm.hdu.edu.cn/showproblem.php?pid=1390
题意:给定一个数n,求它的二进制数的1所处的位置;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>
using namespace std;
int main()
{
int i , j , n;
int Case , num[ 1005 ] , temp[ 1005 ] ;
scanf( "%d" , &Case ) ;
while( Case-- )
{
scanf( "%d" , &n ) ;
int k = 0 ;
while( n )
{
num[ k++ ] = n % 2 ;
n /= 2 ;
}
int m = 0 ;
for( int i = 0 ; i < k ; ++i )
{
if( num[ i ] == 1 )
temp[ m++ ] = i ;
}
for( int i = 0 ; i < m - 1 ; ++i )
printf( "%d " , temp[ i ] );
printf( "%d\n" , temp[ m - 1 ] );
}
return 0 ;
}