提交时间:2024-06-01 16:27:51
运行 ID: 150207
#include<iostream> #include<bits/stdc++.h> using namespace std; int tooct(int n,string s){ int i,t=0; for(int i=0;i<s.size();i++){ if(s[i]>='0' && s[i]<='9') t=t*n+s[i]-48; else if(s[i]>='A' && s[i]<='F') t=t*n+s[i]-55; else if(s[i]>='a' && s[i]<='f') t=t*n+s[i]-87; } return t; } string oct2n(int x,int n){ const string a="0123456789ABCDEF"; string s=""; for(;x>0;x/=n) s=a[x%n]+s; return s; } int main(){ int k,l; string n; while(cin>>k>>n>>l){ int octn=tooct(k,n); string eq=oct2n(octn,l); cout<<eq<<"\n"; } return 0; }