JY's topic (water)

Source: Internet
Author: User

JY's Topic
"Problem Background"
One day, Jy felt Dzy iq too low, decided to divorce him, unless Dzy to make her out of the topic. Dzy of course very want and jy together, so he had to please computer God WJC Help, WJC has helped him several times busy, don't want to help him again. Dzy heard that your programming is also good, so found you. Your task is: To help Dzy solve the problem of JY.

"JY's topic"
"Problem description"
Given two decimal positive integers a and B, calculate how many bits of a and B are different when they are represented in binary notation.
For example, the binary representation of "3" is "11", "9" is represented as "1001", "11" is less than 4 bits, the less part is actually 0, or "0011", so the two are different from right to left 2nd and 4, so 3 and 9 are different in binary notation.

"Input description"
The input consists of two lines, and the 1th line is an integer n, which indicates that there are n sets of test data. Immediately following n rows, each line consists of two decimal positive integers a and b,a, b separated by A space.

"Output description"
The output has n rows and is a different number of bits in binary representation of a and B in each set of test data.

"Sample Input"
1
3 9

"Sample Output"
2

Solving the puzzle: directly to the binary belt comparison just fine.

Code:

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; const int inf=0x3f3f3f3f; #define SI (x) scanf ("%d", &x) #define SL (x) scanf ("%lld", &x) #define PI (x) printf ("%d", X ) #define PL (x) printf ("%lld", x) #define MEM (x, y) memset (x,y,sizeof) #define P_ printf ("") typedef long Long Ll;int main ( {int N,a,b;si (n), while (n--) {si (a); Si (b); int Ans=0;while (a| | b) {if (a%2!=b%2) ans++;a/=2;b/=2;} printf ("%d\n", ans);} return 0;}

  

JY's topic (water)

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.