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

点击消除

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

全部评论

相关推荐

想熬夜的小飞象在秋招:我觉得这模版挺好啊,可以调大点行距,大佬能不能推荐一下是在哪找的模板
应届生,你找到工作了吗
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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