【题目】
【思路】使用堆栈实现N<=10之内的进制转换。
【代码】AC的C++代码如下:
#include <iostream>
#include <stack>
using namespace std;
typedef unsigned long long ULL;
void changeToD(ULL num,int m)
{
stack<int> s;
while (num)
{
s.push(num % m);
num /= m;
}
while (!s.empty())
{
cout << s.top();
s.pop();
}
cout << endl;
}
int main()
{
ULL a,b;
int m;
ULL sum;
while (cin>> m >> a >> b && m != 0)
{
if (a == 0 && b == 0)
{
cout << 0 << endl;
}
else
{
sum = a + b;
changeToD(sum,m);
}
}
return 0;
}