Hdoj 1196 Lowest Bit "&"

Source: Internet
Author: User

Lowest Bit

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9273 Accepted Submission (s): 6824

Problem Description
Given an positive integer a (1 <= a <=), output the lowest bit of a.

For example, given a = +, we can write a in binary form as 11010, so the lowest bit of a is ten, so the output should be 2 .

Another example goes like this:given a = to, we can write A in binary form as 1011000, so the lowest bit of The output should is 8.

Input
Each line of input contains is 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 of a in the input, output A line containing only its lowest bit.

Sample Input
26
88
0

Sample Output
2
8

Test instructions: Output converted to binary non-0-bit
Code:

#include <cstdio>#include <iostream>usingnamespacestd;int main(){    int a;    while(cin >>a, a){        cout << (a&(-a)) <<endl;    }    return0;}

Hdoj 1196 Lowest Bit "&"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.