0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:31:59 +00:00

A/C. 括号匹配

https://xjoi.net/contest/detail/829598
This commit is contained in:
Baoshuo Ren 2021-08-09 10:17:21 +08:00 committed by Baoshuo Ren
parent 50fb86cd78
commit a503db7bf7
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
2 changed files with 8 additions and 8 deletions

View File

@ -4,19 +4,19 @@ using namespace std;
int n, p; int n, p;
string s; string s;
stack<pair<char, int>> st; stack<int> st;
int main() { int main() {
cin >> n >> p >> s; cin >> n >> p >> s;
s = ' ' + s; s = ' ' + s;
for (int i = 1; i < s.size(); i++) { for (int i = 1; i < s.size(); i++) {
if (s[i] == '{') { if (s[i] == '{') {
st.push(make_pair(s[i], i)); st.push(i);
} else if (st.top().second == p) { } else if (st.top() == p) {
cout << i << endl; cout << i << endl;
exit(0); exit(0);
} else if (i == p) { } else if (i == p) {
cout << st.top().second << endl; cout << st.top() << endl;
exit(0); exit(0);
} else { } else {
st.pop(); st.pop();

View File

@ -4,19 +4,19 @@ using namespace std;
int n, p; int n, p;
string s; string s;
stack<pair<char, int>> st; stack<int> st;
int main() { int main() {
cin >> n >> p >> s; cin >> n >> p >> s;
s = ' ' + s; s = ' ' + s;
for (int i = 1; i < s.size(); i++) { for (int i = 1; i < s.size(); i++) {
if (s[i] == '{') { if (s[i] == '{') {
st.push(make_pair(s[i], i)); st.push(i);
} else if (st.top().second == p) { } else if (st.top() == p) {
cout << i << endl; cout << i << endl;
exit(0); exit(0);
} else if (i == p) { } else if (i == p) {
cout << st.top().second << endl; cout << st.top() << endl;
exit(0); exit(0);
} else { } else {
st.pop(); st.pop();