题解 | 二进制不同位数

二进制不同位数

https://www.nowcoder.com/practice/daf9032926614dab91ca624a7759a868

#include<bits/stdc++.h>
using namespace std;

using ui=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128_t;
using u128=__uint128_t;
using ld=long double;

void solve()
{//我们可以把使用异或运算 将两个数异或起来 结果是相同的位数变成0 不同的变成1 最后统计1的个数即可
    ui x,y;
    cin >> x >> y;
    ui ans=x^y;
    cout << __builtin_popcount(ans);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin >> t;
	
	while(t--)
	{
		solve();
	}
	return 0;
}

全部评论

相关推荐

03-03 23:42
复旦大学 Java
_无论云泥意贯一:把复旦大学放前面,山东大学放后面,并且在两个大学后面标注985(用一些显眼的颜色标注)
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务