Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
41974 纪哲弘 二进制转R进制 C++ Accepted 2 MS 276 KB 558 2022-11-12 14:44:17

Tests(10/10):


Code:

#include<iostream> #include<cstring> #include<cmath> using namespace std; void r(string str){ for(int i=str.length()-1;i>=0;i--){ cout<<str[i]; } } string cn(int a,int h){ string b; char c[999]; while(a!=0){ if(a%h>9){ sprintf(c,"%c",55+a%h); } else{ sprintf(c,"%d",a%h); } b.append(c); a/=h; } return b; } using namespace std; int main(){ string ch; int n; cin>>ch>>n; if(ch=="0"){ cout<<0; return 0; } if(n==10){ cout<<stoi(ch,0,2)<<endl; return 0; } r(cn(stoi(ch,0,2),n)); }