zoj 2417 Lowest Bit(简单的模拟)

简介:
Lowest Bit

Time Limit: 2 Seconds       Memory Limit: 65536 KB

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

分析:

(1)因为是100以内的数字所以只要找出能够组成100以内的所有二进制的数字然后一次减直到减后为0时就说明此时减掉的是最小有效位的那个数字。

复制代码
#include <stdio.h>

int main()
{
    int n,bit_num[7],i;
    //得到可以组成100以内的二进制数的组合
    bit_num[0] = 1;
    for(i = 1;i<7;i++)
    bit_num[i] = bit_num[i-1]*2;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        for(i=6;i>=0;i--)
        {
            if(n>=bit_num[i])
            n -= bit_num[i];
            if(n==0)break;
        }
        printf("%d\n",bit_num[i]);
    }
    return 0;
}
复制代码
本文转自NewPanderKing51CTO博客,原文链接: http://www.cnblogs.com/newpanderking/archive/2012/10/05/2712264.html  ,如需转载请自行联系原作者
相关文章
|
4天前
|
云安全 人工智能 算法
以“AI对抗AI”,阿里云验证码进入2.0时代
三层立体防护,用大模型打赢人机攻防战
1319 4
|
4天前
|
机器学习/深度学习 安全 API
MAI-UI 开源:通用 GUI 智能体基座登顶 SOTA!
MAI-UI是通义实验室推出的全尺寸GUI智能体基座模型,原生集成用户交互、MCP工具调用与端云协同能力。支持跨App操作、模糊语义理解与主动提问澄清,通过大规模在线强化学习实现复杂任务自动化,在出行、办公等高频场景中表现卓越,已登顶ScreenSpot-Pro、MobileWorld等多项SOTA评测。
671 3
|
5天前
|
人工智能 Rust 运维
这个神器让你白嫖ClaudeOpus 4.5,Gemini 3!还能接Claude Code等任意平台
加我进AI讨论学习群,公众号右下角“联系方式”文末有老金的 开源知识库地址·全免费
|
11天前
|
编解码 人工智能 自然语言处理
⚽阿里云百炼通义万相 2.6 视频生成玩法手册
通义万相Wan 2.6是全球首个支持角色扮演的AI视频生成模型,可基于参考视频形象与音色生成多角色合拍、多镜头叙事的15秒长视频,实现声画同步、智能分镜,适用于影视创作、营销展示等场景。
776 6
|
8天前
|
物联网 API UED
Qwen-Image-Edit-2511来啦!角色一致性再提升,LoRA能力内置
Qwen-Image-Edit-2511发布!提升角色与多人合照一致性,集成Lora打光、新视角生成,增强工业设计与几何推理能力。已开源,支持魔搭、QwenChat免费体验,本地部署可获最佳效果。
466 3