唔西迪西


私信TA

用户名:dotcpp0670030

访问量:148

签 名:

等  级
排  名 6666
经  验 1337
参赛次数 0
文章发表 7
年  龄 0
在职情况 学生
学  校 燕山大学里仁学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<iostream>

using namespace std;

#define MaxSize 100

typedef struct{

int data[MaxSize];

int top;

}stack;


void InitStack(stack &s){//初始化栈 

s.top=-1;//初始化为-1,也可以初始化为0 

}


bool push(stack &s,int x){//入栈操作 

if(s.top==MaxSize-1){

return false;

}

s.top=s.top+1;

s.data[s.top]=x;

return true;

}


bool StackEmpty(stack s){//判断栈是否为空 

if(s.top==-1){

return true;

}else{

return false;

}

}


bool pop(stack &s,int &x){//出栈操作 

if(s.top==-1){

return false;

}

x=s.data[s.top];

s.top=s.top-1;

return true;

}


int main(){

stack s;//创建一个栈 

InitStack(s);//初始化栈 

int n;

scanf("%d",&n);

while(n>0){

int m=n%8;//当n不为0时,将它的余数入栈 

push(s,m);

n/=8;

}

while(StackEmpty(s)!=true){

int x;

pop(s,x);//再将栈中的元素弹出,直到栈为空 

printf("%d",x);

}

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区