Upload via code

This commit is contained in:
2024-10-03 19:17:29 +08:00
parent 543ccf0fe0
commit b64d31db74
39 changed files with 1548 additions and 0 deletions

50
FZOI/括号匹配.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool f(const string &s)
{
stack<char> st;
for (char c : s)
{
if (c == '(' || c == '[')
{
st.push(c);
}
else if (c == ')' || c == ']')
{
if (st.empty())
{
return false;
}
char top = st.top();
st.pop();
if ((c == ')' && top != '(') || (c == ']' && top != '['))
{
return false;
}
}
}
return st.empty();
}
signed main()
{
string s;
cin >> s;
if (f(s))
{
cout << "OK" << endl;
}
else
{
cout << "Wrong" << endl;
}
return 0;
}