//数制转换:十进制与其他进制进行转换
//算法:N=(N div d)*d + N mod d (其中:div为整除运算,mod为求于运算)
//数据结构用栈
//
#include<iostream>
#include<stack>
using namespace std;
int main()
{
stack<int>S;//栈是模板,要实例化了才能使用
unsigned int n,d;
cout<<"输入要转换的进制:";
cin>>d;
cout<<"输入要转换的数值:";
cin>>n;
while(n)
{
S.push(n%d);
n=n/d;
}
while(!S.empty())
{
cout<<S.top();//pop()的功能好像只有出栈,它并不还回栈顶的值,用top()函数就可以了。
S.pop();
}
return 1;
}