Description
给出一个数n,输出n二进制最低位的值
Input
多组输入,每组用例占一行包括一个整数n,以n=0结束输入
Output
输出lowbit(n)
Sample Input
26
88
0
Sample Output
2
8
Solution
水题,lowbit(n)=n&(-n)
Code
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n),n)
printf("%d\n",n&(-n));
return 0;
}

本文介绍了一个简单的算法问题:如何找出一个整数在二进制表示中最低位的值。通过使用位运算符,文章提供了一种简洁有效的解决方案,并附带了完整的C++实现代码。
805

被折叠的 条评论
为什么被折叠?



