ZOJ Problem Set - 2417 Lowest Bit
来源:互联网 发布:卡密社区系统源码 编辑:程序博客网 时间:2024/05/29 12:04
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
26
88
0
Sample Output
2
8
Author: SHI, Xiaohan
Source: Zhejiang University Local Contest 2005
分析:
题意:
给一个十进制数a要求输出a转换为二进制后它的最低位。如:26=11010(2),它的最低位是2;再如:88=1011000(2),它的最低位是8。有多组测试数据。
短除法模拟一下就知道怎么写代码了。
ac代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n,num;
while(scanf("%d",&n)&&n)
{
num=0;
while(n%2==0)//用短除法试一下十进制转二进制就知道要怎么写代码了
{
n/=2;
num++;
}
printf("%.lf\n",pow(2.0,num*1.0));//pow()函数输出的是double型(返回值是double型)
}
return 0;
}
- ZOJ Problem Set - 2417 Lowest Bit
- zoj 2417 Lowest Bit
- zoj 2417 Lowest Bit
- zoj 2417 Lowest Bit
- ZOJ 2417 Lowest Bit
- ZOJ 2417-Lowest Bit
- zoj 2417 Lowest Bit
- zoj 2417 Lowest Bit
- ZOJ 2417 Lowest Bit
- ZOJ 2417Lowest Bit
- ZOJ Problem Set - 3656 bit magic
- zoj 2417.Lowest Bit
- Problem - 1196 : Lowest Bit
- Problem : 1196 ( Lowest Bit )
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- 【BZOJ 1030】 [JSOI2007]文本生成器
- hadoop权威指南,天气数据文件自动下载下载
- Interleaving String|leetcode题解
- subsys_initcall宏定义的一个例子,acpi/bus.c里面。
- 低功耗蓝牙4.0BLE编程-nrf51822开发(8)-GATT
- ZOJ Problem Set - 2417 Lowest Bit
- 《iOS极光推送步骤》
- JS鼠标事件(监听鼠标点击/释放,鼠标悬停/离开等)
- Unity API 笔记
- 内部类,匿名内部类
- Jocky for Eclipse
- 啊哈C——学习3.2一起来找茬
- 一些算法题
- Go语言实现跳表(SkipList)