1 条题解
-
0
C++ :
#include <cstdio> #include <iostream> #include <string> #include <cstring> #include <cmath> #define for1( i , a , b ) for( int i = a ; i <= b ; i++ ) #define for2( i , a , b ) for( int i = a ; i >= b ; i-- ) using namespace std ; class Jack { public: void play() ; protected: int t , n , s , s1 , sum , w , a[ 40 ]; } ; void Jack::play() { //freopen( "in.txt" , "r" , stdin ) ; //freopen( "out.txt" , "w" , stdout ) ; cin >> t ; while( t-- ) { memset( a , 0 , sizeof( a ) ) ; cin >> n ; s = 0 ; while( n ) { a[ s++ ] = n % 2 ; n /= 2 ; } //for1( i , 0 , s ) cout << a[ i ] << ' ' ; //cout << endl ; s1 = s - 1 ; while( a[ s1 ] == 0 ) s1-- ; w = 1 , sum = 0 ; for2( i , s1 , 0 ) sum += w * a[ i ] , w <<= 1 ; printf( "%d\n" , sum ) ; } } int main() { Jack jack ; jack.play() ; return 0 ; }
Python :
# coding=utf-8 n=int(input()) for i in range(n): a=int(input()) b=bin(a) b2=b[2:] b3=b2[::-1] a2=int(b3,2) print(a2)
- 1
信息
- ID
- 3381
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者