题解 | #点击消除#利用栈的思维就行

点击消除

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;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:29
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
07-11 10:56
门头沟学院 Java
码客明:大胆的说自己能实习6个月就行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务