3554. 二进制

思路

(32)位二进制数转换为十进制数,用long long存储(n+1)(n+3)的结果(不超过(33)位),再将结果转成二进制即可。

void solve(LL n)
{
    for(int i=32;i>=0;i--)
    {
        int t=n>>i & 1;
        if(i == 32 && !t) continue;
        cout<<t;
    }
    cout<<endl;
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        
        LL n=0;
        for(auto c:s) n=n*2+c-'0';
        solve(n+1);
        solve(n+3);
    }

    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14810636.html