进制转换
作者:
三行四列行列式
,
2023-06-20 10:44:52
,
所有人可见
,
阅读 138
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define MaxSize 100000
typedef struct {
int top;
char data[MaxSize];
}SqStack;
void InitStack(SqStack &s){
s.top=-1;
}
bool EmptyStack(SqStack s){
if(s.top== -1 ) return true;
else return false;
}
bool Push(SqStack &s,int &e){
if(s.top == MaxSize - 1) return false;
s.data[++s.top]=e;
return true;
}
bool Pop(SqStack &s,int &e){
if(EmptyStack(s)) return false;
e=s.data[s.top--];
return true;
}
void exChange(int n,int x){
SqStack s;
InitStack(s);
while(n){
int m = n%x;
Push(s,m);
n/=x;
}
int e;
while(EmptyStack(s)==0){
Pop(s,e);
printf("%d",e);
}
}
int main(){
exChange(1348,8);
return 0;
}