直接用的STL模板,改天再用算法库试试!
代码:
#include<bits/stdc++.h>
using namespace std;
stack<int> s;
int main()
{
int a,b;
while(cin>>a>>b)
{
while(a/b!=0)
{
s.push(a%b);
a=a/b;
}
s.push(a%b);
while(!s.empty())
{
cout<<s.top();
s.pop();
}
cout<<endl;
}
return 0;
}
知识点总结:
十进制转任何进制的数都可以用这个方法,一开始还以为这是辗转相除法;有谁知道这个方法的学名?
心得体会:
少说多做!