比赛 板子大赛 评测结果 AAAAAA
题目名称 多种括号匹配 最终得分 100
用户昵称 AeeE5x 运行时间 0.018 s
代码语言 C++ 内存使用 3.31 MiB
提交时间 2025-01-22 09:16:17
显示代码纯文本
#include<iostream> 
#include<stack>
using namespace std;
int f(char x){
    if(x=='('||x==')') return 1;
    return 2;
}
bool ilg(string s){
    stack<int> st;
    for(int i=0;i<s.length();i++){
        if(s[i]=='('||s[i]=='[') st.push(f(s[i]));
        else{
            if(st.empty()) return false;
            if(st.top()!=f(s[i])) return false;
            st.pop();
        }
    }
    return st.empty();
}
int main(){
    freopen("check.in","r",stdin);
    freopen("check.out","w",stdout);
    
    string s;cin>>s;
    if(ilg(s)) cout<<"OK";
    else cout<<"Wrong";
        
    return 0;
}