AcWing 3554. 二进制
原题链接
简单
作者:
yvr
,
2021-05-24 23:55:35
,
所有人可见
,
阅读 151
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
void output(ll n){
for(int i=32;i>=0;i--){ 由于只是进行了n+1和n+3运算,最多输入的二进制运算后最多是33位,不会超过33位,所以从33位(下标是32)开始为起点继续判断即可
int t=n>>i & 1; // 选出n的二进制形式的每一位对其进行判断
if(!t && i==32) continue; //如果出现超过32位的并且更高位是0的话,不需要进行输出
cout<<t;
}
puts("");
}
int main(){
int T;
cin>>T;
while(T--){
ll n=0;
string s;
cin>>s;
for(auto c:s) n = n*2 + c-'0';
output(n+1);
output(n+3);
}
return 0;
}