文章

65

粉丝

25

获赞

670

访问

24.8k

头像
括号的匹配 题解:111
P1067 中山大学机试题
发布于2025年3月14日 14:57
阅读数 334

#include <bits/stdc++.h>
using namespace std;
map<char,char> m1{
{'>','<'},{')','('},{']','['},{'}','{'}
};
map<char,int> m2{
{'<',1},{'(',2},{'[',3},{'{',4}
};
void khpp(string s){
    stack<char> st;
    int flag=1;//YES!!!
    for(int i=0;i<s.size();i++){
        if(s[i]=='<' || s[i]=='(' || s[i]=='[' || s[i]=='{'){//左压 
            if(st.empty()==1||m2[s[i]]<=m2[st.top()]) {//注意:判断栈空应该在前,由于开始时top没有值,故而会溢出 
                                                       // 注意:[[]]是对的,...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发