You are on page 1of 3

#include "stdafx.

h"
#include"stdlib.h"
#include"iostream"
using namespace std;
#include"malloc.h"
typedef int status;
int e,n;
//quanju
typedef struct{
int *base;
int *top;
int stacksize;
}sqstack;
status initstack(sqstack &s)
{ s.base=(int *)malloc(100*sizeof(int));
if(!s.base) exit(-2);
s.top=s.base;
s.stacksize=100;
return 1;
}
status push(sqstack &s,int &e)
//??
{ if(s.top-s.base>=s.stacksize)
{s.base=(int *)realloc(s.base,(s.stacksize+10)*sizeof(int));
if(!s.base) exit(-2);
s.top=s.base+s.stacksize;
s.stacksize+=10;
}
*s.top++=e;
return 1;
}
status gettop(sqstack &s,int &e)
{ if(s.top==s.base) return 0;
e=*(s.top-1);
return 1;

//??????

}
status pop(sqstack &s,int &e)
//??
{ if(s.top==s.base) return 0;
e=*--s.top;
return 1;
}
void jinzhi()
//????????
{ int m,k,w,q,a,p;
char b[39]={"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
sqstack s1;
initstack(s1);
cout<<"???????(2-36)****???(int ???)*****????????(2-36)"<<endl;
cin>>m>>k>>w;
q=0;
p=1;
while(k)
{ a=k%10;
k/=10;
q+=a*p;
p*=m;
}
while(q)
{ e=q%w;
push(s1,e);
q/=w;

}
while(s1.base!=s1.top)
{pop(s1,e);
cout<<b[e];
}
cout<<endl;
}
int main()
{ sqstack s;
int i,j,tt;
do
//????
{ system("cls");
system("color 1e");
cout<<"
?????"<<endl;
cout<<"
1.??"<<endl;
cout<<"
2.??????"<<endl;
cout<<"
3.????????????"<<endl;
cout<<"
4.????-????(2-36)"<<endl;
cout<<"?????????:";
cout<<"?????:";
cin>>i;
system("cls");
switch(i)
{
case 1: system("color 4e");
initstack(s);
cout<<"?????:";
cin>>n;
cout<<"???"<<n<<"??"<<endl;
for(j=0;j<n;j++)
{ cin>>e;
push(s,e);
}
getchar();
cout<<"??????????";
getchar();
break;
case 2: system("color 5e");
gettop(s,e);
cout<<"???????:"<<e<<endl;
getchar();
cout<<"??????????";
getchar();
break;
case 3: system("color 7e");
cout<<"??????: ";
cin>>tt;
push(s,tt);
gettop(s,e);
cout<<"???????:"<<e<<endl;
for(j=0;j<n;j++)
{ pop(s,e);
cout<<e<<" ";
}
getchar();
cout<<"??????????";
getchar();
break;

case 4:

system("color 6e");
jinzhi();
getchar();
cout<<"??????????";
getchar();
break;

}
}while(i==1||i==2||i==3||i==4);

system("color 1e");

return 0;
}

You might also like