0
Перевод с языка С++ на язык Python
I need to translate a programm to Python #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s; cin >> n >> s; stack<char> st; map<char, char> ma; ma[')'] = '('; ma[']'] = '['; ma['}'] = '{'; for (int i = 0; i < s.size(); ++i) { if (s[i] == '(' || s[i] == '[' || s[i] == '{') st.push(s[i]); else if (!st.empty() && st.top() == ma[s[i]]) st.pop(); else { cout << "No" << endl; return 0; } } if (!st.empty()) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
2 ответов
0
n = int(input())
s = input()
st = []
ma = {')': '(', ']': '[', '}': '{'}
for i in range(len(s)):
if s[i] in ['(', '[', '{']:
st.append(s[i])
elif len(st) > 0 and st[-1] == ma[s[i]]:
st.pop()
else:
print("No")
exit(0)
if len(st) > 0:
print("No")
else:
print("Yes")