文章

38

粉丝

11

获赞

2

访问

17.4k

头像
栈(匹配),vector(记录,修改)题解:
P1296 北京大学机试题
发布于2024年9月17日 10:50
阅读数 178

#include<bits/stdc++.h>
using namespace std;
map<char,char> match = {
    {
        '(',')'
    }
};
int main(){
    string s;
    int len;
    while(getline(cin,s)){
        stack<char> st;
        len = s.size();
        vector<int> a;// ( = 0, ) = 1, 字符  = 2
        for(int i = 0;i < len;i++){
            if(s[i] == '(') {
                st.push(s[i]);
                a.push_back(0);//右括号,直接压入0
            }
            else if(s[i] == ')'){
                if(!st.empty() && s[i] == match[st.top()]){
         ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发