• 【小米OJ-括号配对】栈的使用


    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        // please write your code here
        stack<int>st;
        string str;
        while(cin>>str){
            while(!st.empty()) st.pop();
            for(int i=0;i<str.size();i++){
              if(st.empty()) st.push(str[i]);
              else if(st.top()=='['&&str[i]==']') st.pop();
              else if(st.top()=='('&&str[i]==')') st.pop();
              else if(st.top()=='{'&&str[i]=='}') st.pop();
              else st.push(str[i]);
            }
            if(st.empty()) cout<<1<<endl;
            else cout<<0<<endl;
        }
        return 0;
    }
    

      

    不忘初心,方得始终。只有走过弯路,才更确信当初最想要的是什么。
  • 相关阅读:
    Python格式化字符 %s %d %f
    FTP学习笔记
    万维网
    TCP笔记
    TCP流量控制
    笔记传输层
    传输层协议
    网络层
    以太网笔记
    计算机网络物理层
  • 原文地址:https://www.cnblogs.com/wszhu/p/12804377.html
Copyright © 2020-2023  润新知