Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <iostream>
- #include <vector>
- #include <stack>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 2e5 + 10;
- const int N = 2e5;
- char invert(char c) {
- if (c == ')') {
- return '(';
- }
- if (c == ']'){
- return '[';
- }
- if (c == '}') {
- return '{';
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- string s;
- cin >> s;
- stack<char> st;
- for (int i = 0; i < s.size(); ++i) {
- if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
- st.push(s[i]);
- } else {
- if (st.empty() || invert(s[i]) != st.top()) {
- cout << "no\n";
- return 0;
- } else {
- st.pop();
- }
- }
- }
- cout << (st.empty() ? "yes\n": "no\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment