题解 | 点击消除

点击消除

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

#include <iostream>
using namespace std;
#include <stack>
#include <string>
int main(){
    string s;
    cin>>s;
    stack<char>a;
    for(char c:s){
        if(!a.empty()&&a.top()==c)a.pop();
        else a.push(c);
    }
    string res;
    while(!a.empty()){
        res=a.top()+res;
        a.pop();
    }
    cout<<(res.empty()?"0":res)<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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