Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <stack>
- #include <queue>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- string n;
- cin >> n;
- stack <char> s;
- for(int i = 0; i < n.size(); i++) {
- if(n[i] == '(' or n[i] == '{' or n[i] == '[') {
- s.push(n[i]);
- }
- if(n[i] == ')') {
- if(!s.empty() and s.top() == '(') {
- s.pop();
- }
- else {
- cout << "NE" << endl;
- return 0;
- }
- }
- if(n[i] == ']') {
- if(!s.empty() and s.top() == '[') {
- s.pop();
- }
- else {
- cout << "NE" << endl;
- return 0;
- }
- }
- if(n[i] == '}') {
- if(!s.empty() and s.top() == '{') {
- s.pop();
- }
- else {
- cout << "NE" << endl;
- return 0;
- }
- }
- }
- if(s.empty()) {
- cout << "DA" << endl;
- }
- else {
- cout << "NE" << endl;
- }
- return 0;
- }
- // ({})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement