HDU1196+二进制转换

水~

View Code
 1 /*

 2 a转化为二进制

 3 */

 4 #include<stdio.h>

 5 #include<string.h>

 6 #include<stdlib.h>

 7 #include<algorithm>

 8 #include<iostream>

 9 #include<queue>

10 #include<vector>

11 #include<map>

12 #include<math.h>

13 typedef long long ll;

14 //typedef __int64 int64;

15 const int maxn = 105;

16 const int maxm = 1005;

17 const int inf = 0x7FFFFFFF;

18 const double pi = acos(-1.0);

19 const double eps = 1e-8;

20 

21 int get_lowbit( int num ){

22     int bit[ maxn ];

23     int cnt = 0;

24     while( num ){

25         bit[ cnt++ ] = num%2;

26         num/=2;

27     }

28     int ans = 1;

29     for( int i=0;i<cnt;i++ ){

30         if( bit[i]==0 ){

31             ans*=2;

32         }

33         else break;

34     }

35     return ans;

36 }

37 int main(){

38     int num;

39     while( scanf("%d",&num)==1 ,num ){

40         printf("%d\n",get_lowbit( num ) );

41     //    return 0;

42     }

43     return 0;

44 }

 

你可能感兴趣的:(进制转换)