算法1
只可能有一个前导1,无符号整数判定即可。
C++ 代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T=0;
char c = '1';
while(c = getchar(),c>='0' && c<='9') T = (T*10) + c-'0';
unsigned int x;
while(T--)
{
x = 0;
while(c = getchar(),c=='0' || c=='1') x = (x<<1) + c-'0';
unsigned int y = x;
x++;
if(y > x)cout<<"1";
for(int i = 31 ; i>=0;i--)cout<< ((x>>i)&1?"1":"0") ;cout<<endl;
x++;x++;
if(y > x)cout<<"1";
for(int i = 31 ; i>=0;i--)cout<< ((x>>i)&1?"1":"0") ;cout<<endl;
}
}