Problem L: 操作次数

来源:互联网 发布:淘宝otc药品货到付款 编辑:程序博客网 时间:2024/05/27 14:12

Description

给定两个正整数(二进制表示形式)A和B,你可以进行操作把任意一位从0变成1或者从1变成0,问把A变为B最少需要进行几次操作。

Input

多组输入,每组输入A,B(0<=A,B<=1000000)。

Output

最少的操作次数。

Sample Input

2 3
4 7

Sample Output

1
2

#include <iostream>#include <cstdio>using namespace std;int main(){    int a,b;    while(scanf("%d %d",&a,&b)!=EOF){        int res=0;        if(a==0&&b==0)            res=0;        else{        while(a!=0||b!=0){        if(a%2 != b%2)        res++;        a=a>>1;        b=b>>1;        }    }     cout<<res<<endl;}    return 0;}
0 0
原创粉丝点击