题解 | #点击消除#

点击消除

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

#include <iostream>
#include <string>
#include <deque>
using namespace std;

int main() {
    std::string str;
    cin >> str;
    std::string ret;
  	//使用双端队列
    std::deque<char> tmp;
    for(auto it : str){
        if(!tmp.empty() && it == tmp.back()){
            tmp.pop_back();
        }
        else{
            tmp.push_back(it);
        }
    }
    while(!tmp.empty()){
        ret += tmp.front();
        tmp.pop_front();
    }
    if(ret.empty()){
        std::cout << 0 << std::endl;
    }else{
        std::cout << ret << std::endl;
    }
    
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

Sigma429:极兔啊,薪资开的巨低,还在上海,索性不做笔试了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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