hdu 1196 Lowest Bit
2024-10-15 21:15:18
题目连接
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 ;
}
最新文章
- -XX:+printGC
- linux下文件编码的查看与修改
- h5-2
- 教了几天C语言 C语言竞赛------家长们你们为什么这么急!!
- 每天一个linux命令:mkdir
- Android_按钮被按下效果的实现(selector选择器)
- Docker简明教程(转)
- Secondary Namenode - What it really do?
- 1132: 零起点学算法39——多组测试数据(a+b)
- 小白的Python之路 day1 用户输入
- centos7.2 配置内网ntp服务器进行时间同步
- js数组去除重复
- webpack使用三
- div中 li宽度不固定 ie6和ie7不兼容不自动换行
- 【CF744D】Hongcow Draws a Circle 二分+几何
- jquery如何获取第一个或最后一个子元素
- thinkjs项目中使用mongoose需要注意的地方
- java面试题(开发框架)
- SqlServer——字符串处理函数
- spring源码学习之:springAOP实现底层原理
热门文章
- Android——Runtime类中的freeMemory,totalMemory,maxMemory等几个方法
- Jsp servlet 值传递。。
- HTTP Status 500 - javax.servlet.ServletException
- ASP.NET验证控件二
- ADO.NET中的DataSet和DataAdapter
- POJ C++程序设计 编程题#1 编程作业—继承与派生
- Java 中的构造方法
- 一款jQuery特效编写的大度宽屏焦点图切换特效
- wordpress学习-themes-001
- “Unable to resolve target &#39;android-9&#39;”的问题