//數制轉換:十進制與其他進制進行轉換
//算法: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;
}