• hdu 1196 Lowest Bit


    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=1196

    Lowest Bit

    Description

    Given an positive integer $A (1 leq A leq 100)$, output the lowest bit of $A.$

    For example, given $A = 26$, we can write $A$ in binary form as $11010$, so the lowest bit of $A$ is $10$, so the output should be $2$.

    Another example goes like this: given $A = 88$, we can write $A$ in binary form as $1011000$, so the lowest bit of $A$ is $1000$, so the output should be $8$.

    Input

    Each line of input contains only an integer $A (1 leq A leq 100).$ $A$ line containing $"0"$ indicates the end of input, and this line is not a part of the input data.

    Output

    For each A in the input, output a line containing only its lowest bit.

    Sample Input

    26
    88
    0

    Sample Output

    2
    8

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<map>
     8 #include<set>
     9 using std::set;
    10 using std::map;
    11 using std::cin;
    12 using std::cout;
    13 using std::endl;
    14 using std::find;
    15 using std::sort;
    16 using std::pair;
    17 using std::vector;
    18 #define sz(c) (int)(c).size()
    19 #define all(c) (c).begin(), (c).end()
    20 #define iter(c) decltype((c).begin())
    21 #define cls(arr,val) memset(arr,val,sizeof(arr))
    22 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    23 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    24 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    25 #define pb(e) push_back(e)
    26 #define mp(a, b) make_pair(a, b)
    27 const int Max_N = 100010;
    28 typedef unsigned long long ull;
    29 int main() {
    30 #ifdef LOCAL
    31     freopen("in.txt", "r", stdin);
    32     freopen("out.txt", "w+", stdout);
    33 #endif
    34     int n, ans;
    35     while (~scanf("%d", &n) && n) {
    36         ans = 1;
    37         while (true) {
    38             if (n & 1) break;
    39             ans <<= 1;
    40             n >>= 1;
    41         }
    42         printf("%d
    ", ans);
    43     }
    44     return 0;
    45 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    12306-单
    12306-票
    12306-车
    12306-人
    12306-目录
    a+=b 是什么意思?
    开启hadoop和Hbase集群的lzo压缩功能(转)
    HBase性能优化方法总结(转)
    Spark向HDFS中存储数据
    Spark从HDFS上读取JSON数据
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4594117.html
Copyright © 2020-2023  润新知