zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence

    题目链接:http://codeforces.com/contest/612/problem/C

    解题思路:

    题意就是要求判断这个序列是否为RBS,每个开都要有一个和它对应的关,如:<()>满足条件,但<(>)就不满足条件,反正直接就是用栈做就行了,完美符合题目要求。

    #include <bits/stdc++.h>
    using namespace std;
    stack<char>st;
    /*struct node{
        int num,id;
    }a[200009];
    bool cmp(const node x,const node y){
        return x.num<y.num;
    }*/
    int main()
    {
        string s;
        cin>>s;
        int ans =0,i;
        for(i=0;i<s.size();i++){
            if(s[i] == ']'){
                if(st.size() == 0)  return puts("Impossible");
                if(st.top() == '[')
                    st.pop();
                else{
                    ans++; st.pop();
                }
            }
            else if(s[i]=='>'){
                if(st.size() == 0)  return puts("Impossible");
                if(st.top() == '<')
                    st.pop();
                else{
                    ans++; st.pop();
                }
            }
            else if(s[i]=='}'){
                if(st.size() == 0)  return puts("Impossible");
                if(st.top() == '{')
                    st.pop();
                else{
                    ans++; st.pop();
                }
            }
            else if(s[i]==')'){
                if(st.size() == 0)  return puts("Impossible");
                if(st.top() == '(')
                    st.pop();
                else{
                    ans++; st.pop();
                }
            }
            else
                st.push(s[i]);
        }
        if(st.size()==0)
        cout<<ans<<endl;
        else
        cout<<"Impossible"<<endl;
    }
  • 相关阅读:
    CSS 3 中的多列属性
    CSS3 3D转换
    CC3中的2D转换
    ubuntu sudo: pip:找不到命令
    ubuntu 下更新pip后发生 ImportError: cannot import name 'main'的问题解决
    ubuntu 安装pip
    gradle下载
    L0,L1,L2正则化浅析
    安装使用离线版本的维基百科(Wikipedia)
    Linux中CPU亲和性(affinity)
  • 原文地址:https://www.cnblogs.com/kls123/p/7131495.html
Copyright © 2011-2022 走看看