题解 | #点击消除#
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
#include <stdio.h> #include <string.h> int main() { int a, b; int top = -1; static char chr1[300000] = { 0 }; static char chr2[300000] = { 0 }; while (scanf("%s", chr1) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to for(int i = 0; i < strlen(chr1); i++) { if(top == -1) { chr2[++top] = chr1[i]; } else if(chr1[i] == chr2[top]) { top--; } else { chr2[++top] = chr1[i]; } } if ( top == -1) printf("0"); else for (int j = 0; j <= top; j++) { printf("%c", chr2[j]); // 输出栈中剩余的内容 } } return 0; }