比赛 板子大赛 评测结果 AAAAAA
题目名称 多种括号匹配 最终得分 100
用户昵称 秋_Water 运行时间 0.019 s
代码语言 C++ 内存使用 3.29 MiB
提交时间 2025-01-22 12:15:57
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
string s;
stack<char>st;
int main(){
    freopen("check.in","r",stdin);
    freopen("check.out","w",stdout); 
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]==')'){
            if(!st.empty()&&st.top()=='('){
                st.pop();
            }
            else{
                cout<<"Wrong";
                return 0;
            }
        }
        else if(s[i]==']'){
            if(!st.empty()&&st.top()=='['){
                st.pop();
            }  
            else{
                cout<<"Wrong";
                return 0;
            }         
        }
        else{
            st.push(s[i]);
        }
    }
    if(st.empty()){
        cout<<"OK";
    }
    else{
        cout<<"Wrong";
    }
        
    return 0;
}