#include
#include
#include
#include
#include
struct node
{
int data;
struct node *next;
};
int main()
{
int count=0;
char a[80];
scanf("%s",a);
struct node *p,*q,*h;
h= (struct node *)malloc(sizeof(struct node));
p= (struct node *)malloc(sizeof(struct node));
q= (struct node *)malloc(sizeof(struct node));
h->next = p;
for(int i=strlen(a)-1;i>0;i--)//倒序读取二进制数并存入单链表
{
p->data = a[i] - '0';//将char类型转化为int
p->next = q;
p = p->next;
q = (struct node *)malloc(sizeof(struct node));
}
p->data = a[0] - '0';//最后一个结点的特殊处理
p->next = NULL;
p = h->next;
int j=0;
while(j
if(p->data == 0)
{
p->data = 1;
break;
}
else {
if(p->next == NULL)
{
q = (struct node *)malloc(sizeof(struct node));
q->data = 1;
q->next = NULL;
p->next = q;
p->data = 0;
break;
}
else {
p->data = 0;
p=p->next;
}
}
}
p = h->next;
for(;p->next!=NULL;count++)//count计算单链表的长度
{
p = p->next;
}
p = h->next;
for(int m=0;m<=count;m++)//倒序输出单链表的数据
{
for(int n=m;n
p = p->next;
}
printf("%d",p->data);
free(p);
p = h->next;
}
return 0;
}