题解 | #点击消除#利用栈的思维就行
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
#include <stdio.h> #include <string.h> int main() { char str[300000]; // 假设字符数组的大小为300000 scanf("%s", str); // 读取字符串并存储到数组 int strLength = strlen(str); // 获取输入字符串的长度 char stack[300000]; int top = -1; for (int i = 0; i < strLength; i++) { if (top == -1 || str[i] != stack[top]) { stack[++top] = str[i]; } else { top--; } } if (top == -1) { printf("0"); } else { for (int i = 0; i <= top; i++) { printf("%c", stack[i]); } } return 0; }