#include<stdio.h>
#include<assert.h>
#include<stdbool.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
typedef int STDateType;
typedef struct Stack{
STDateType*a;
int top;
int capacity;
} ST;
void StackInit(ST* ps){
assert(ps);
ps->a=NULL;
ps->top=0;
ps->capacity=0;
}
void StackDestory(ST* ps){
assert(ps);
free(ps->a);
ps->a=NULL;
ps->top=ps->capacity=0;
}
void StackPush(ST* ps,STDateType x){
assert(ps);
if(ps->capacity==ps->top){
int NewCapacity=ps->capacity==0?4:ps->capacity*2;
STDateType* temp=(STDateType*)realloc(ps->a,sizeof(STDateType)*NewCapacity);
if(temp==NULL){
printf("realloc fail");
exit(-1);
}
ps->a=temp;
ps->capacity=NewCapacity;
}
ps->a[ps->top]=x;
ps->top++;
}
bool StackEmpty(ST* ps){
assert(ps);
return ps->top==0;
}
void StackPop(ST* ps){
assert(ps);
assert(!StackEmpty(ps));
ps->top--;
}
STDateType StackTop(ST* ps){
assert(ps);
assert(!StackEmpty(ps));
return ps->a[ps->top-1];
}
int StackSize(ST* ps){
assert(ps);
return ps->top;
}
int main () {
printf("20级8班20220751337陈俊豪\n");
int n,i,t,sum,j;
sum=0;
printf("input:");
scanf("%d",&n);
ST st;
StackInit(&st);
for(t=n;t>0;t=t/10){
StackPush(&st,t%10);
}
for(i=StackSize(&st)-1;!StackEmpty(&st);i--){
sum=sum+StackTop(&st)*(int)pow(2,(double)i);
StackPop(&st);
}
printf("转为二进制为;%d",sum);
return 0;
}