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
| #include <iostream>
using namespace std;
int fun1(char a) { if (a == 'A') return 10; if (a == 'B') return 11; if (a == 'C') return 12; if (a == 'D') return 13; if (a == 'E') return 14; if(a=='F') return 15; return int(a - '0'); }
char fun2(int a) { if (a == 10) return 'A'; if (a == 11) return 'B'; if (a == 12) return 'C'; if (a == 13) return 'D'; if (a == 14) return 'E'; if (a == 15) return 'F'; return char (a + '0'); }
int main() { long long n, m, p = 1, sum = 0; string s, res = "";
cin >> n >> s >> m;
for (int i = s.size() - 1; i >= 0; i --) { sum += fun1(s[i]) * p ; p *= n; } while (sum != 0) { res = fun2(sum % m) + res; sum /= m; }
cout << res << endl;
return 0; }
|