Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <cmath>
- #include <iostream>
- #include <iterator>
- #include <map>
- #include <set>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <stack>
- #define int long long
- #define pb push_back
- using namespace std;
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s;
- cin >> s;
- stack<int> st;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
- st.push(s[i]);
- }
- if (s[i] == ')' || s[i] == ']' || s[i] == '}') {
- if (st.top() == s[i]) {
- st.pop();
- } else {
- cout << "no";
- return 0;
- }
- }
- }
- if (st.size() == 0) {
- cout << "yes";
- } else {
- cout << "no";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment