parent
88e6f068d7
commit
6134e22de8
@ -1,2 +1,61 @@
|
||||
# 1
|
||||
#include<stdlib.h>
|
||||
#import <MobileCoreServices/MobileCoreServices.h>
|
||||
|
||||
#define maxsize 100
|
||||
typedef struct
|
||||
{
|
||||
int *base;
|
||||
int *top;
|
||||
int stacksize;
|
||||
} sqstack;
|
||||
|
||||
void initstack(sqstack &s)
|
||||
{
|
||||
s.base = malloc(maxsize*sizeof(int));
|
||||
if(!s.base)exit;
|
||||
s.top=s.base;
|
||||
s.stacksize=maxsize;
|
||||
}
|
||||
|
||||
void push(sqstack &s,int e){
|
||||
if(s.top-s.base==s.stacksize)return;
|
||||
*s.top++=e;
|
||||
return;
|
||||
}
|
||||
|
||||
void pop(sqstack &s,int &e){
|
||||
if(s.top==s.base)return;
|
||||
e=*--s.top;
|
||||
return;
|
||||
}
|
||||
|
||||
void zhuanhuan(sqstack &a,int e){
|
||||
int temp;
|
||||
while(e!=0){
|
||||
temp=e%16;
|
||||
push(a,temp)
|
||||
e=e/16;
|
||||
}
|
||||
string str;
|
||||
while(s.top==s.base){
|
||||
int n=0;
|
||||
pop(a,n)
|
||||
if(n>=10){
|
||||
str = char('A'-10+n)+str;
|
||||
}
|
||||
else{
|
||||
str=char('0'+n)+str
|
||||
}
|
||||
}
|
||||
cout << "转化后的十六进制数如下" << endl;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int a=0;
|
||||
sqstack* y=(sqstack*)malloc(sizeof(sqstack));
|
||||
initstack(y);
|
||||
cout << "请输入想要转化的十进制数字" << endl;
|
||||
cin >> a;
|
||||
zhuanhuan(y,a)
|
||||
}
|
||||
}
|
Loading…
Reference in new issue