//
// main.cpp
// stack_数制转换
//
// Created by 王寿年 on 15/9/26.
// Copyright © 2015年 王寿年. All rights reserved.
//
#include <iostream>
using namespace std;
#define stack_init_size 100
typedef struct {
int *top;
int *base;
int stacksize;
}Stack;
void StackInit(Stack &s)
{
s.base = new int[stack_init_size];
s.top = s.base;
s.stacksize = stack_init_size;
}
bool StackFull(Stack &s)
{
if((int)(s.top - s.base) >= s.stacksize)
return true;
else
return false;
}
bool StackEmpty(Stack &s)
{
if(s.top == s.base)
return true;
else
return false;
}
void push(Stack &s,int e)
{
if(StackFull(s) == true)
{
cout << "栈已经满了" << endl;
exit(-2);
}
*s.top++ = e;
}
void pop(Stack &s,int &e)
{
if(StackEmpty(s) == true)
{
cout << "栈已经空了" << endl;
exit(-2);
}
e = *--s.top;
}
int StackLength(Stack &s)
{
return (int)(s.top - s.base);
}
void StackDestory(Stack &s)
{
if(s.base)
{
delete []s.base;
s.top = s.base = NULL;
s.stacksize = 0;
}
}
void StackClear(Stack &s)
{
s.top = s.base;
}
void conversion()
{
Stack s;
StackInit(s);
int n;
cin >> n;
int m;
cin >> m;
while(n)
{
push(s,n % m);
n /= m;
}
while(!StackEmpty(s))
{
int e;
pop(s,e);
cout << e;
}
cout << endl;
StackDestory(s);
}
void GetTop(Stack &s,int &e)
{
if(StackEmpty(s) == true)
{
cout << "栈已经空了" << endl;
exit(-2);
}
e = *(s.top - 1);
}
int main()
{
conversion();
return 0;
}