#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 300001
typedef struct SNode{
int top; //栈顶元素下标
int capacity; //元素个数
char str[M];
}SNode;
typedef SNode*Stack;
void Push(Stack s,char a)
{
if(s->capacity==0)
{
s->top++;
s->capacity++;
s->str[s->top]=a;
}
else {
if(s->str[s->top]==a) //消除步骤
{
s->top--;
s->capacity--;
}
else {
s->top++;
s->capacity++;
s->str[s->top]=a;
}
}
}
int main()
{
char first_str[M];
Stack s=(Stack)malloc(sizeof(struct SNode));
s->capacity=0;
s->top=-1;
scanf("%s",first_str);
int len=strlen(first_str);
for(int i=0;i<len;i++)
{
Push(s,first_str[i]);
}
if(s->capacity==0)
printf("0\n");
else
{
for(int i=0;i<s->capacity;i++)
{
printf("%c",s->str[i]);
}
}
}
写得不太规范,欢迎指正。