#include <iostream> #define MAXN 1000 using namespace std; char code[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int stack[MAXN];//栈 int top = -1; //判断栈空 bool isempty(){ return top < 0; } //出栈 int pop(){ int r = stack[top]; top--;//指针下移 return r; } //入栈 void push(int value){ top++; stack[top] = value; } //转换:n转换为d进制 void conversion(int n,int d){ while(n != 0){ push(n % d); n = n / d; } } int main(){ int n,d; cin>>n>>d; conversion(n,d); if(isempty()){ cout<<0<<endl; }else{ //输出栈的内容 while(!isempty()){ cout<<code[pop()]; } cout<<endl; } return 0; } /************************************************************** Problem: 1415 User: admin Language: C++ Result: Accepted Time:30 ms Memory:2076 kb ****************************************************************/