比赛 板子大赛 评测结果 AAWAAA
题目名称 多种括号匹配 最终得分 83
用户昵称 chenbp 运行时间 0.018 s
代码语言 C++ 内存使用 3.32 MiB
提交时间 2025-01-22 14:34:56
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack <char>st;
int main(){
    freopen("check.in","r",stdin);
    freopen("check.out","w",stdout);
    string s;
    cin>>s;
    int len=s.size();
    for(int i=0;i<len;i++){
        if(s[i]=='('||s[i]=='[') st.push(s[i]);
        else{
            if(s[i]==']'){
                if(!st.empty()&&st.top()=='['){
                    st.pop();
                }else{
                    cout<<"Wrong";
                    return 0;
                }
            }
            if(s[i]==')'){
                if(!st.empty()&&st.top()=='('){
                    st.pop();
                }else{
                    cout<<"Wrong";
                    return 0;
                }
            }
        }
    }
    cout<<"OK";
    return 0;
}
/*int main(){
    freopen("check.in","r",stdin);
    freopen("check.out","w",stdout);
    string s;
    cin>>s;
    int x=s.find("()");
    int y=s.find("[]");
    while(x!=-1||y!=-1){
        if(x!=-1) s.erase(x,2);
        else if(y!=-1) s.erase(y,2);
        x=s.find("()");
        y=s.find("[]");cout<<s<<endl;
    }
    if(s.empty()){
        cout<<"OK";
    }else{
        cout<<"Wrong";
    }
    return 0;
}*/