zoukankan      html  css  js  c++  java
  • 奇怪的键盘(2015蓝桥杯)

                                                         奇怪的键盘

                                                                         Time Limit: 1 Sec  Memory Limit: 128 MB
            
                                                                                        [Submit][Status][Discuss]

    Description

    近期科学家们在熬夜写论文报告,可是不争气的键盘出现了一系列的问题,有的时候点一下键盘往外出两个字符,有的时候只出一个。恰巧键盘的退格键坏了。
    你知道科学家们都是有怪脾气的,他自己打出一篇文章,他就像恢复成原来的.
    科学家满意的字符串是这样的,如果字符串中有相临的两个字符相同就消除这两个字符,形成一个新的字符串,如果新的字符串还有相邻的字符并且相同,再消除。一直到没有相邻的两个字符相同为止。

    Input

    一个字符串,长度不大于2*10^5,只包含小写字母

    Output

    令科学家满意的字符串。

    Sample Input

    reallazy

    Sample Output

    rezy

    HINT

    对于样例中的字符串这样变化的,reallazy -> reaazy -> rezy.

    类似于括号匹配,用栈就可以了。

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <cstdlib>
    #include <map>
    #include <queue>
    #include <stack>
    using namespace std;
    const int MAXN=2e5+10;
    char a[MAXN];
    stack<char> st,q;
    int main()
    {
        gets(a);
        int len=strlen(a);
        for(int i=0;i<len;i++)
            if(st.empty()||st.top()!=a[i])
                st.push(a[i]);
            else
                st.pop();
        while(!st.empty())
        {
            q.push(st.top());
            st.pop();
        }
        while(!q.empty())
        {
            cout<<q.top();
            q.pop();
        }
        return 0;
    }
    
    
    
    
  • 相关阅读:
    java线程读取文件,可以同时读写 202006031002
    JS,JQuery bug202005282020
    js,jquery缩小加载的图片202005131907
    spring boot/spring cloud + mybatis + mysql bug 20200513
    html2020042901,table元素之间的间距
    ie8-ie11浏览器bug2020042801
    css的bug2020042801
    xml读取解析bug20200423
    Poi读取word(doc)文档的文本或图片
    NOI2020专题
  • 原文地址:https://www.cnblogs.com/jk17211764/p/9677365.html
Copyright © 2011-2022 走看看