文章
68
粉丝
19
获赞
376
访问
45.1k
注意开long long,其实就是统计二进制中0的个数,如果输入为0高位不补1,否则高位补1
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
LL t, n;
int main()
{
cin >> t;
while (t --)
{
cin >> n;
LL tmp = n;
int cnt = 0;
vector<int> w;
while (tmp > 0)
{
if (tmp % 2 == 0) cnt ++;
tmp /= 2;
}
for (int i = 0; i < cnt; i ++) w.push_back(0);
if (n != 0) w.push_back(1);
else w.push_back(0);
for (int i = w.size()-1; i >= 0; i --) cout << w[i];
cout << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发