Bit Problem

题目描述

As everyone knows, any non-zero integer’s binary representation, must have at least one bit of the data 1, XiaoMing process whom wants to know if a binary representation of the rightmost 1 can change to 0, How much is this number will reduce.
But now, XiaoMing, busy job, no time to YY this question, so as ACMer your duty bound to help him solve this problem.
 

输入

Input consists of several cases, For each case, the first input is an integer N, then with N lines thar each integer is non zero integer. N=0 indicates the end of the input.
 

输出

For each set of case, we need to output N data corresponding to each row of data representation, the corresponding data in the most the 1 change 0, again resulting from the difference between the results with the original data. Each data finally output a blank line.
 

示例输入

2
9
3

5
19999
456
10000000
1
8

0

示例输出

Answer to case1:
1
1

Answer to case2:
1
8
128
1
8
//题意:求一个数转化为二进制,在最右边的1改为0,变化之后得到的数减少了多少
//标程:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
//	freopen("a.txt","r",stdin);
	int cnt(0), n, i, x;
	int flag(0);
    while(cin >> n && n)
	{
		cnt ++;
		if(flag == 1) cout << endl;
		printf("Answer to case%d:\n",cnt);
		flag = 1;
		for(i = 1; i <= n; i ++)
		{
			cin >> x;
			int j = 0, ans = 1, k;
			while(x)
			{
                                k = x % 2;
				if(k == 1) break;
                                ans *= 2;
				x /= 2;
				
			}
		    cout << ans << endl;
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值