#include <iostream> #include <string> #include <algorithm> using namespace std; void divide2(string s, string& res, int& remain) { res.clear(); int local = 0; for (int i = 0; i < s.length(); i++) { local = local * 10 + s[i] - '0'; if (local < 2) { //到这里,不能除 if(!res.empty()) res = res + '0';//上0 } else { res = res + to_string(local / 2); local = local % 2; } } remain = local; } int main() { // 模拟除2取余法 string s; string out; string res; int remain; cin >> s; while (true) { divide2(s, res, remain); out = to_string(remain) + out; if (res == "") break; s = res; } cout << out << endl; out.clear(); }