题解 | #点击消除#

点击消除

https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 300000
typedef struct stacknode {
    char data;
    struct stacknode* next;
} Stack, *StackNode;
void Stackpop(StackNode* s) {
    StackNode p = (Stack*)malloc(sizeof(Stack));
    p = *s;
    *s = (*s)->next;
    free(p);
    p=NULL;
}
void Stackpush(StackNode* s, char c) {
    StackNode p = (Stack*)malloc(sizeof(Stack));
    p->data = c;
    p->next = *s;
    *s = p;
}
int main() {
    StackNode s=NULL;
    StackNode p=NULL;
    char str[N];
    scanf("%s", str);
    for (int i = 0; i < strlen(str); i++) {
        if (s==NULL) {
            Stackpush(&s, str[i]);
        } else if (s->data == str[i]) {
            Stackpop(&s);
        } else {
            Stackpush(&s, str[i]);
        }
    }
    if (s== NULL) {
        printf("0\n");
    } else {
        while (s != NULL) {
            Stackpush(&p, s->data);
            s=s->next;
        }
        while (p!=NULL) {
            printf("%c",p->data);
            p=p->next;
        }
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 14:00
不想多说了,什么逆天HR,还要教我礼貌😂
机械打工仔:这不纯傻卵吗,他还操心上别人老板了
投递BOSS直聘等公司9个岗位
点赞 评论 收藏
分享
Yki_:你要算时间成本呀,研究生两三年,博士三四年,加起来就五六年了,如果你本科去腾讯干五年,多领五年的年薪,加上公司内涨薪,可能到时候十五年总薪资也跟博士差不多
点赞 评论 收藏
分享
Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:55
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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