当然是用栈 和 c字符串耗时更短啦!
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
const int N = 200010;
char a[N];
char tmp[N];
char stk[N];
int top = -1;
// stack<char> stk;
int main()
{
scanf("%s", a);
int n = strlen(a);
for(int i = 0; i < n; i++)
{
bool flag = true;
if(top != -1 && a[i] == stk[top])
{
top--;
flag = false;
}
if(flag) stk[++top] = a[i];
}
int cnt = 0;
while(top != -1)
{
tmp[cnt++] = stk[top];
top--;
}
for(int i = cnt - 1; i >= 0; i--)
printf("%c", tmp[i]);
return 0;
}