Last active
August 19, 2019 13:41
-
-
Save TonyPepeBear/d630e3b8d5292616d6bfa6a637112547 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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