先转换成long long,然后从高位到低位把每一位抠出来输出,注意一下33位的情况即可
C++ 代码
#include <iostream>
using namespace std;
typedef long long LL;
void output(LL n)
{
if (n >> 32 & 1) cout << 1; //最高位可能有33位
for (int i = 31; i >= 0; i -- )
{
cout << (n >> i & 1);
}
cout << endl;
}
int main()
{
int T;
string s;
cin >> T;
while (T -- )
{
cin >> s;
LL n = 0;
for (int i = 0; i < s.length(); i ++ )
{
n <<= 1;
n |= s[i] - '0';
}
output(n + 1);
output(n + 3);
}
return 0;
}