代码实现
#include <iostream>
using namespace std;
const int maxNum = 100;
typedef struct Stack {
int data[maxNum];
int top;
} Stack;
void initStack(Stack &s) {
s.top = -1;
}
void push(Stack &s, int x) {
if (s.top == maxNum - 1)
return;
else {
s.data[++s.top] = x;
}
}
bool pop(Stack &s, int &k) {
if (s.top == -1)
return false;
k = s.data[s.top--];
return true;
}
bool stackIsEmpty(Stack s) {
if (s.top == -1)
return true;
else
return false;
}
int main() {
int n;
cin >> n;
Stack s;
initStack(s);
while (n) {
push(s, n % 8);
n = n / 8;
}
while (!stackIsEmpty(s)) {
int k;
pop(s, k);
cout << k;
}
return 0;
}