AC
2025-03-24 21:29:29
发布于:山西
0阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int n, idx;
ull k;
int bin[100];
int ans[100];
stack<int> s;
int main() {
cin.tie(0);
cin>>n>>k;
while (k > 0) {
s.push(k % 2);
k /= 2;
}
while (!s.empty()) {
bin[++idx] = s.top();
s.pop();
}
for (int i = 1; i <= idx; ++i) {
if (bin[i] == bin[i - 1]) {
ans[i] = 0;
} else {
ans[i] = 1;
}
}
for (int i = 1; i <= n - idx; ++i) {
cout << 0;
}
for (int i = 1; i <= idx; ++i) {
cout << ans[i];
}
}
这里空空如也
有帮助,赞一个