您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: