题意:给一个数n, 求出该数二进制表示(binary notation)的最低位的1的权值。
这道题用简单的位操作即可求解,倘若挨个测试,就有些慢了。
题目URL:http://acm.hdu.edu.cn/showproblem.php?pid=1196;
这是我的AC代码:
#include<iostream>
using namespace std;
int lowestBit(int num)
{
return num & (num ^ (num - 1));
}
int main()
{
int num;
while(scanf("%d", &num) && num)
{
printf("%d\n", lowestBit(num));
}
system("pause");
return 0;
}