HDU 1196
2016-07-17 11:21
274 查看
Lowest Bit
[align=left]Problem Description[/align]Given an positive integer A (1 <= A <= 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.
化成二进制,把最后一个1往后的都取出来输出;其实就相当是这个数能被多少个2整除。
再次我就基本位运算了。
#include<stdio.h> int main() { int n; while(~scanf("%d",&n)&&n) { int sum=1; while(n==(n>>1)<<1) { n>>=1; sum<<=1; } printf("%d\n",sum); } return 0; }
相关文章推荐
- 前端资讯与资源
- html框架的使用
- is_int出现的问题
- php文件创建相关操作
- [2]一切都是对象
- 1小时教你突破写作瓶颈,成为文案高手
- array DEMO
- [c#基础]AutoResetEvent
- JavaEE中表现层、持久层、业务层的职责分析(转载)
- PHP页面跳转几种实现技巧
- 小白张的博客开篇
- javascript字符串和数组转换
- Android 所有权限大全
- isKindOfClass和isMemberOfClass的区别
- 自定义ToolBar
- Android动画学习之LayoutAnimation三
- CodeForces 501B - Misha and Changing Handles
- PHP ob系列函数(缓存输出函数)详解
- AngularJs中,如何在render完成之后,执行Js脚本
- 自学——PaintAndPath