Skip to content

Instantly share code, notes, and snippets.

@TonyPepeBear
Last active August 19, 2019 13:41
Show Gist options
  • Save TonyPepeBear/d630e3b8d5292616d6bfa6a637112547 to your computer and use it in GitHub Desktop.
Save TonyPepeBear/d630e3b8d5292616d6bfa6a637112547 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <list>
using namespace std;
string convert(int n, int m) {
list<int> num;
while (n > 0) {
num.push_front(n % m);
n /= m;
}
string ans;
for (int a : num) {
if (a > 10) {
ans.push_back((char) a + 87);
} else {
ans.append(to_string(a));
}
}
return ans;
}
int main() {
int n = 0, m = 0;
while (cin >> n >> m) {
cout << "The base " << m << " representation of " << n << " is " << convert(n, m) << "." << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment