题解 | #点击消除#

点击消除

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

#include <iostream>
#include <memory>
using namespace std;
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define maxsize 300000
typedef struct
{
    char* top;
    char* base;
}stack;
void initstack(stack &s)
{
    s.base=new char[maxsize];
    s.top=s.base;
}
void pushstack(stack &s,char e)
{
    if(*(s.top-1)!=e||s.top==s.base)
    {
    *s.top=e;
    s.top++;
    }
    else 
        s.top=s.top-1;
}
int main() 
{
    int lengh,i,n;
    stack s;
    initstack(s);
    char a[300000];
    scanf("%s",a);
    lengh=strlen(a);
    for(i=0;i<lengh;i++)
    {
        pushstack(s,a[i]);
    }
    if(s.top==s.base)
    printf("0");
    else
    {
        n=s.top-s.base;
        for(i=0;i<=n-1;i++)
        printf("%c",*(s.base+i));
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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