#include <iostream> #include<string> using namespace std; string add(string A, string B) { //A, B为逆序 string C; int t = 0; for(int i = 0; i < A.size() || i < B.size(); i++) { if(i < A.size()) t += A[i] - '0'; if(i < B.size()) t += B[i] - '0'; C += t % 10 + '0'; t /= 10; } if(t) C += t + '0'; return C; } string mul2(string A) { //输入输出均为逆序 string C; int t = 0; for(int i = 0; i < A.size(); i++) { t += (A[i] - '0') * 2; C += t % 10 + '0'; t /= 10; } while(t) { C += t % 10 + '0'; t /= 10; } while(C.size() > 1 && C.back() == '0') C.pop_back(); return C; } string div2(string A, int& r) { string C; r = 0; for (int i = 0; i < A.size(); i++) { r = r * 10 + A[i] - '0'; C += r / 2 + '0'; r %= 2; } while (C.size() > 1 && C[0] == '0') C.erase(0, 1); return C; } int main() { string A, bin; //bin为逆序 cin >> A; while (A != "0") { int r = 0; A = div2(A, r); bin += r + '0'; } // for (int i = bin.size() - 1; i >= 0; i--) cout << bin[i]; string base = "1", res = "0"; for(int i = bin.size() - 1; i >= 0; i--) { //将bin逆序排列进行转换 if(bin[i] == '1') res = add(res, base); base = mul2(base); } for(int i = res.size() - 1; i >= 0; i--) cout << res[i]; return 0; }