模拟问题 使用数组模拟输出的数值,超过10的数位输出字符型
AC代码
#include<iostream>
using namespace std;
//#include<string>
int str[10000];
int main()
{
int n, r, i, flag, x;
while (cin>>n>>r)
{
flag = 0;
if (n < 0)
{
n = -n;
flag = 1;
}
x = 0;
while (n > 0)
{
str[x] = n%r;
n /= r;
x++;
}
if (flag)
{
cout << "-";
}
while (x--)
{
if (str[x] < 10)
{
cout << str[x];
}
else
{
cout << (char)(55 + str[x]);
}
}
cout << endl;
}
return 0;
}