#include<iostream>

#include<assert.h>

using namespace std;


template<class ItemType>

struct NodeType;

template<class ItemType>

class StackType

{

public: 

StackType();

~StackType();

void push(ItemType jungsu, ItemType jinsu);

void pop();

ItemType Top();

bool IsFull() const;

bool IsEmpty() const;


private:

NodeType* topPtr;

};

template<class ItemType>

struct NodeType{

ItemType info;

NodeType* next;

};

template<class ItemType>

StackType<ItemType>::StackType()

{

topPtr = NULL;

}template<class ItemType>

StackType<ItemType>::~StackType()

{

NodeType* tempPtr;

while (topPtr != NULL)

{

tempPtr = topPtr;

topPtr = topPtr->next;

delete tempPtr;

}

}

template<class ItemType>

void StackType<ItemType>::push(ItemType jungsu, ItemType jinsu)

{

if (IsFull())

cout << "Error : the Stack is Full" << endl;

else

{

while (jungsu > 0)

{

NodeType* location;

location = new NodeType;

location->info = jungsu%jinsu;

jungsu = jungsu / jinsu;

location->next = topPtr;

topPtr = location;

}

}

}

template<class ItemType>

void StackType<ItemType>::pop()

{

if (IsEmpty())

{

cout << "Error : The Stack Is Empty" << endl;

}

else

{

NodeType* tempPtr;

tempPtr = topPtr;

topPtr = topPtr->next;

delete tempPtr;

}

}

template<class ItemType>

ItemType StackType<ItemType>::Top()

{

if (IsEmpty())

cout << "Error : The Stack Is Empty 표시할 것 이없습니다." << endl;

else

return topPtr->info;

}

template<class ItemType>

bool StackType<ItemType>::IsEmpty() const{

if (topPtr == NULL)

return true;

else

return false;

}template<class ItemType>

bool StackType<ItemType>::IsFull() const

{

NodeType* location;

try

{

location = new NodeType;

delete location;

return false;

}

catch (std::bad_alloc exception)

{

return true;

}

}

template<class ItemType>

int main()

{

StackType convert;

ItemType jungsu, jinsu;

cout << "정수와 진수를 차례대로 입력하세요(16진수 이상)";

cin >> jungsu >> jinsu;

assert(jinsu <= 16);

assert(jungsu > 0 && jinsu > 0);

convert.push(jungsu, jinsu);

while (!convert.IsEmpty())

{

if (convert.Top() == 10){

cout << 'A';

convert.pop();

}

else if (convert.Top() == 11){

cout << 'B';

convert.pop();

}

else if (convert.Top() == 12){

cout << 'C';

convert.pop();

}

else if (convert.Top() == 13){

cout << 'D';

convert.pop();

}

else if (convert.Top() == 14){

cout << 'E';

convert.pop();

}

else if (convert.Top() == 15){

cout << 'F';

convert.pop();

}

else

{

cout << convert.Top();

convert.pop();

}

}

cout << endl;

return 0;


}