剑指offer——面试题15.2:判断两个整数m和n的二进制中相差多少位
作者:互联网
1 #include"iostream" 2 using namespace std; 3 4 int CountDifferentBit(int m,int n) 5 { 6 int cnt=0,diff=m^n; 7 while(diff) 8 { 9 cnt++; 10 diff=(diff-1)&diff; 11 } 12 return cnt; 13 } 14 15 int main() 16 { 17 int m,n; 18 while(cin>>m>>n) 19 { 20 cout<<CountDifferentBit(m,n)<<endl; 21 } 22 return 0; 23 }View Code
标签:面试题,cout,offer,int,cnt,15.2,while,diff 来源: https://www.cnblogs.com/acm-jing/p/10402873.html