AcWing 3373. 进制转换
原题链接
中等
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
vector<int> vec;
vector<int> ans;
string st;
vector<int> _div() {
vector<int> res;
int siz = vec.size();
res.push_back(vec[0] / 2);
vec[0] %= 2;
for (int i = 1; i < siz; i++) {
res.push_back(vec[i - 1] * 10 + vec[i]);
vec[i] = res.back() % 2;
res.back() /= 2;
}
while (!res.empty() && res.front() == 0)res.erase(res.begin());
return res;
}
void solve() {
while (cin >> st) {
vec.clear();
ans.clear();
for (char& ch : st)vec.push_back(ch - '0');
do {
ans.push_back(vec.back() % 2);
vec = _div();
} while (!vec.empty());
reverse(ans.begin(), ans.end());
for (int& num : ans)cout << num;
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}