http://acm.hdu.edu.cn/showproblem.php?pid=2031
此题我利用了STL的stack。
#include <iostream> #include <stack> //STL using namespace std; int main() { int a,b; while (cin>>a>>b) { int i; char j; stack<int> st; if (a<0) //若是负数,输出负号 { a=-a; cout<<"-"; } while (a!=0) { i=a%b; a=a/b; st.push(i); //入栈 } while (!st.empty()) //判空 { if (st.top()>9) { j=st.top()+55; cout<<j; //输出字母 } else cout<<st.top(); //输出栈顶元素 st.pop(); //移除栈顶元素 } cout<<endl; } return 0; }