小菜最近复习数据结构~~~
很简单的东西还是要敲阿
就这样 po代码
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define Stack_Init_Size 20
#define Stack_Increasement 10
typedef char Elemtype;
typedef struct{
Elemtype *base;
Elemtype *top;
int stackSize;
}sqStack;
void InitStack(sqStack *s){
s->base=(Elemtype *)malloc(Stack_Init_Size*sizeof(Elemtype));
if(!s->base)
exit(0);
s->top=s->base;
s->stackSize=Stack_Init_Size;
}
int stackLen(sqStack s){
return (s.top-s.base);
}
void push(sqStack *s,Elemtype e){
if(s->top-s->base>=s->stackSize){
s->base=(Elemtype *)realloc(s->base,(Stack_Increasement+s->stackSize)*sizeof(Elemtype));
if(!s->base)
exit(0);
}
*(s->top)=e;
s->top++;
}
void pop(sqStack *s,Elemtype *e){
if(s->top==s->base){
return;
}
s->top--;
*e=*(s->top);
}
int isEmpty(sqStack *s){
return s->top==s->base;
}
int main(){
sqStack s,t;
Elemtype c;
InitStack(&s);
InitStack(&t);
scanf("%c",&c);
while(c!='#'){ //当输入# 输入结束 以字符读入
push(&s,c);
scanf("%c",&c);
}
getchar();
int sum;
int i,j;
int slen=stackLen(s);
for(i=0;i<slen;i+=3){
sum=0;
for(j=0;j<3;j++){
if(!isEmpty(&s))
{
pop(&s,&c);
sum+=(c-48)*(int)pow(2,j);
}
}
push(&t,sum+48);
}
int tlen=stackLen(t);
for(i=0;i<tlen;i++){
pop(&t,&c);
printf("%c",c);
}
return 0;
}