题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/0337e32b1e5543a19fa380e36d9343d7
#include<cstdio>
#include<string>
#include<iostream>
#include<vector>
using namespace std;
int main(){
string str;
while (cin >> str){
vector<int>ans;
int k=0;
if (str == "0"){
printf("0\n");
continue;
}
while (!str.empty()){
for (int i = 0; i < str.size(); i++){
int t = k;
k = (str[i] - '0' + k * 10) % 2;
str[i] = (str[i] - '0' + t * 10) / 2 + '0';
}
if (str[0] == '0'){
str.erase(0,1);
}
ans.push_back(k);
k = 0;
}
for (int i = ans.size() - 1; i >= 0; i--){
printf("%d", ans[i]);
}
printf("\n");
}
}
