1
2
3
4
5
6
7
8
9
10
11
12
13
14
| string convNotation(const string &s, int from, int to) {
int n = stoll(s, nullptr, from);
if (n == 0)
return "0";
string result;
while (n) {
result += n % to < 10 ? '0' + n % to : 'A' + n % to - 10;
n /= to;
}
if (s[0] == '-')
result += '-';
reverse(result.begin(), result.end());
return result;
}
|