题解 | #点击消除#
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
#include
#include
struct{
char chars[300000];
int topIdx;
}str={{0},0};
int main(){
scanf("%s",str.chars);
int len=strlen(str.chars);
char *string=(char *)malloc(sizeof(char)*len);
for(int i=0;i<len;i++){
string[str.topIdx++]=str.chars[i];
if(str.topIdx>1){
if(string[str.topIdx-1]==string[str.topIdx-2])
str.topIdx-=2;
}
}
if(str.topIdx==0)
printf("0");
else{
for(int i=0;i<str.topIdx;i++)
printf("%c",string[i]);
}
return 0;
}