题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/0337e32b1e5543a19fa380e36d9343d7
#include <iostream> #include <string> #include <algorithm> //#define ll long long using namespace std; string myDivide(string todo,int x=2); int main() { ios::sync_with_stdio(false); cin.tie(0); string todo,ans; while (cin >> todo) { ans.clear(); while(todo!="") { ans.push_back(((todo[todo.size()-1]-'0')%2)+'0'); todo=myDivide(todo); } reverse(ans.begin(),ans.end()); cout<<ans<<endl; } } string myDivide(string todo,int x) { int reminder=0,pos=0; for(int i=0;i<todo.size();++i) { int temp=(todo[i]-'0')+reminder*10; todo[i]=temp/x+'0'; reminder=temp%x; } while(todo[0]=='0') { todo.erase(0,1); } return todo; }