题目连接

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

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::set;
using std::map;
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::pair;
using std::vector;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
const int Max_N = ;
typedef unsigned long long ull;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n, ans;
while (~scanf("%d", &n) && n) {
ans = ;
while (true) {
if (n & ) break;
ans <<= ;
n >>= ;
}
printf("%d\n", ans);
}
return ;
}

hdu 1196 Lowest Bit的更多相关文章

  1. hdu 1098 Lowest Bit 解题报告

    题目链接:http://code.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=2&problemid=22 ...

  2. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. HDOJ 1196 Lowest Bit(二进制相关的简单题)

    Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. F ...

  4. hdu 1196

    Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. F ...

  5. HDU 2028 Lowest Common Multiple Plus

    http://acm.hdu.edu.cn/showproblem.php?pid=2028 Problem Description 求n个数的最小公倍数.   Input 输入包含多个测试实例,每个 ...

  6. 【HDOJ】1196 Lowest Bit

    水题,原理是计算机组成原理中的负数的补码的求码.利用按位与可解. #include <iostream> using namespace std; int main() { int n; ...

  7. Problem : 1196 ( Lowest Bit )

    第一次一次通过,逻辑太简单... #include<iostream> using namespace std; void main() { int n; while(cin>> ...

  8. HDOJ 1196 Lowest Bit

    题目大意是给一个1-100的整数,要求首先转化成2进制,然后从最低位开始数起到不是0的位停止,输出这些位代表队额10进制数 #include <iostream> using namesp ...

  9. 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)

    也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...

随机推荐

  1. 全局变量 urllib模块 json模块

    1.vars()  查看一个.py文件中的全局变量 print(vars()) #重点 __name__': '__main__ '__file__': 'C:/Users/lenovo/Pychar ...

  2. SQL 表值函数

    表值函数返回的是一张表. 情况:把传入的字符串按指定分隔符转换成数组 理解:把字符串打散,逐个插入表,这个表就是需要的数据 Create Function [dbo].[Split] ( ), ) ) ...

  3. X86 架构和 ARM 架构

    1.关于x86架构 X86是一个intel通用计算机系列的标准编号缩写,也标识一套通用的计算机指令集合,X86是由Intel推出的一种复杂指令集,用于控制芯片的运行的程序,现在X86已经广泛运用到了家 ...

  4. oracle数据库中的表设置主键自增

    oracle中没有自增字段,可通过序列+触发器间接实现,cmd中sqlplus登录,直接运行即可.一般要经过一下几步: 1建立数据表 create table Test_Increase(       ...

  5. SQL:每年每月最高的两个温度

    SET QUOTED_IDENTIFIER ONGO CREATE TABLE [dbo].[Temperature]( [ID] [int] IDENTITY(1,1) NOT NULL, [Mon ...

  6. 操作系统学习笔记 对称多处理(SMP)

    SMP:一种通过复用处理器提高程序执行并行性的方式. 根据SMP,计算机系统可以分为以下四类: 单指令单数据流(SISD):一个单处理器执行一个单指令流,对保存在一个存储器中的数据进程进行操作. 单指 ...

  7. JNI基础概念以及原理-2016.01.11

    Java到C数据类型转换 1 基础类型 Java与Jni类型对应关系 2 String到char数组 具体使用方式 JNIEXPORT jstring JNICALL Java_com_zhoulee ...

  8. js 全选全不选

     checkAll: function () { //全选         if ($("#chk_SelectAll").is(":checked")) { ...

  9. std::cout彩色输出

    Mac OS效果 Windows 效果 想写这个东西其实是因为最近要写个命令行的工具,但是有个问题是什么呢?就是传统的那个黑漆漆的窗口看起来很蛋疼.并且完全看不到重点,于是就想起 来这么一个东西.相对 ...

  10. C++多态性——函数的覆盖和隐藏

    1.函数的覆盖 覆盖的条件: 基类函数必须是虚函数(使用Virtual关键字进行声明): 发生覆盖的两个函数必须分别位于派生类和基类中: 函数名称与参数列表必须完全一样: 2.函数的隐藏 隐藏,是指派 ...