#include<iostream>
using namespace std;
#define dataType char
char ch[17] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B','C', 'D', 'E', 'F','G'};
class Stack
{
private:
dataType *data;
int top;
dataType* bottom;
int lenth ;
public:
Stack(int MaxSize = 10000+1){
data = new dataType[MaxSize];
lenth = MaxSize-1;
bottom = data;
top = 0;
}
~Stack(){
delete data;
cout<<"destruct successfully!"<<endl;
}
void Get_len(int &e){
e = top;
}
int Get_len(){
return top;
}
void IsEmpty()
{
if(top == 0){
cout<<"Stack is empty"<<endl;
}
else{
cout<<"Stack is not empty"<<endl;
}
}
void PushStack(dataType e)
{
if(top == lenth){
cout<<"Stack is full<<endl";
exit(-1);
}
else{
top++;
data[top] = e;
}
}
void PopStack(dataType &e)
{
if(top == 0){
cout<<"Stack is empty"<<endl;
}
else{
e = data[top];
top--;
}
}
Stack(Stack &_Stack){
this->top = _Stack.top;
for(int i = 0; i<=_Stack.lenth; i++){
this->data[i] = _Stack.data[i];
}
this->bottom =this->data;
lenth = _Stack.lenth;
}
};
int main()
{
Stack* S = new Stack();
int DS_WillBeFormat = 0;// DS---"进制"
int DS_Formated = 0;
cout<<"The DS you want to format:"<<endl;
cin>>DS_WillBeFormat;
cout<<"to what?"<<endl;
cin>>DS_Formated;
string num_WillBeFormat ;
int num_Formated = 0;
cout<<"The DS number you want to format: "<<endl;
cin>>num_WillBeFormat;
int sum = 0;
int _DS_WillBeFormat = 1;
for(int i = num_WillBeFormat.length()-1; i>=0; i--){
int n = 0;
for(int j = 0; j<=DS_WillBeFormat-1; j++){
if(num_WillBeFormat[i] == ch[j]){
n = j;
break;
}
}
sum += n*_DS_WillBeFormat;
_DS_WillBeFormat *= DS_WillBeFormat;
}
cout<<sum<<endl;
dataType Remainder;
while(sum){
Remainder = sum % DS_Formated;
S->PushStack(ch[Remainder]);
sum /= DS_Formated;
}
cout<<"The number you want is :"<<endl;
int L = 0;
S->Get_len(L);
dataType n2 = 0;
for(int i = 1; i<=L; i++){
S->PopStack(n2);
cout<<n2;
}
cout<<endl;
delete S;
cout<<"helloworld";
system("pause");
return 0;
}
纯手撸
别骂