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