B3884 [信息与未来 2015] 加数 题解

· · 题解

这题先初始化再模拟n/2的过程就行了。
直接上代码。

#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(){
    cin>>n;
    for(int i=n;i>0;i=i/10)
        s+=char((n%10)+'0');
    while(n>0)
    {
        n=n/2;
        for(int i=n;i>0;i=i/10)
            s+=char((n%10)+'0');
    }
    cout<<s.size();
    return 0;
}