0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 14:18:47 +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;
string s;
stack<pair<char, int>> st;
stack<int> st;
int main() {
cin >> n >> p >> s;
s = ' ' + s;
for (int i = 1; i < s.size(); i++) {
if (s[i] == '{') {
st.push(make_pair(s[i], i));
} else if (st.top().second == p) {
st.push(i);
} else if (st.top() == p) {
cout << i << endl;
exit(0);
} else if (i == p) {
cout << st.top().second << endl;
cout << st.top() << endl;
exit(0);
} else {
st.pop();

View File

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