题目描述
简单的进制转换
C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
string itoa(int n)
{
string ans;
do
{
if (n % 13 < 10) ans += n % 13 + '0';
else ans += n % 13 - 10 + 'A';
n /= 13;
} while(n);
reverse(ans.begin(), ans.end());
return ans;
}
int main()
{
int a[3];
string s[3];
cin >> a[0] >> a[1] >> a[2];
cout << "#";
for (int i = 0; i < 3; i ++)
{
s[i] = itoa(a[i]);
while (s[i].size() < 2) s[i] = "0" + s[i];
cout << s[i];
}
}