1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #include<bits/stdc++.h> using namespace std;
inline void conversion(string &str){ for(int i = 0;i < str.length()/2;i++){ swap(str[i],str[str.length()-1-i]); } }
void conversion_M_10(int m,string x,int &num){ conversion(x); for(int i = 0;i < x.length();i++){ if(x[i] >= '0' && x[i] <= '9'){ num = num + (x[i]-'0')*pow(m,i); } else{ num = num + (x[i]-'A'+10)*pow(m,i); } } }
void conversion_10_n(int n,int num,string &s){ int i=0;char ch; while(num){ ch = fmod(num,n); if(ch < 10) ch = ch + '0'; else if(ch>'a'&&a<'z') ch = ch + 'a' - 10; else if(ch>'A'&&a<'Z') ch = ch + 'A' - 10; s=s+ch; num=num/n; } conversion(s); } int main() { int m,n,num = 0;string x1,x2; cin>>m>>x1; conversion_M_10(m,x1,num); cout << num <<endl; cin>>n;
conversion_10_n(n,num,x2);
cout<<x2; return 0; }
|