進制轉換:
#include<iostream>
#include<stack>
using namespace std;
int main(){
int n,m;
stack<char> st;
while(cin>>n>>m){
int temp;
if((n<0&&m>0)||(n>0&&m<0))
cout<<"-";
while(n){
temp=n%m;
temp=temp>0?temp:-temp;
if(temp>=10)
st.push(temp-10+'A');
else
st.push(temp+'0');
n/=m;
}
while(!st.empty()){
cout<<st.top();
st.pop();
}
cout<<endl;
}
return 0;
}本文出自 “菜鳥的進階之路” 博客,請務必保留此出處http://beyond316.blog.51cto.com/7367775/1272552