Lowest Bit
Problem Description
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.
Input
Each line of input contains only an integer A (1 <= A <= 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
Sample Output
Author
SHI, Xiaohan
Source
Recommend
Ignatius.L
大水题!很简单!直接发代码!
#include<iostream>
using namespace std;
int main()
{
int num,sum,i,j,temp;
while(cin>>num && num!=0)
{
sum=1;temp=0;
for(i=1;temp==0;i++)
{
temp=num%2;
//arr[i]=num%2;
num=num/2;
}
//cout<<"i="<<i<<endl;
//for(;;i--)
//if(arr[i]==1)
//break;
for(j=1;j<i-1;j++)
sum=sum*2;
cout<<sum<<endl;
}
return 0;
}
分享到:
相关推荐
杭电oj1000题解题报告
这是杭电oj入门100题的题号,通过这100题可以掌握基本输入输出操作,及基本算法
杭电OJ题目分类的叙述,可以方便去学习去做。
杭电oj 1047习题
杭电OJ 2028代码 the rosolve of the hdu 2028
本资源主要提供了杭电oj题目分类和自测状况两大类 可实现随机选题等功能.
杭电OJ(1000-1099) AC 代码
杭电oj上的一些疑问,适用于初学者,可以解答一些疑问 都是一些水题
杭电OJ部分威士忌的代码 杭电OJ部分威士忌的代码杭电OJ部分威士忌的代码
杭州电子科大OJ题目汇总,个人编辑,题目不多,相对简单
[生活]杭电oj部分水题 c语言源代码
杭州电子科技大学 oj离线版
杭电oj分类
这是HDUOJ上面的140道题目的答案,其中大部分都是简单题,有些太简单的就没有收集进去,代码为C/C++,全都AC了的,其中有些有具体的说明是怎么做的,例如博弈论那些
杭电ACM2000-2011题已提交的代码!保证正确!
课程资源 杭电OJ1000-1099答案 ,仅供参考...
杭电oj的离线版以及题目分类的文档 更加一目了然 方便选择适合的题目做 适合暂时上不了网的用于练习
这是杭电OJ上某些题的解题报告,后续还有上传很多!