-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcp27.cpp
46 lines (44 loc) · 888 Bytes
/
dcp27.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<stack>
#include<bits/stdc++.h>
using namespace std;
struct braces
{
char start;
char close;
};
int main()
{
stack <int> st;
char str[100];
cin >> str;
struct braces ar[3];
ar[0].start = '(';
ar[0].close = ')';
ar[1].start = '[';
ar[1].close = ']';
ar[2].start = '{';
ar[2].close = '}';
for ( int i = 0; str[i] != '\0'; i++) {
if ( str[i] == ar[0].start )
st.push(str[i]);
else if ( str[i] == ar[1].start )
st.push(str[i]);
else if ( str[i] == ar[2].start )
st.push(str[i]);
else if( str[i] == ar[0].close && st.top() == ar[0].start )
st.pop();
else if( str[i] == ar[1].close && st.top() == ar[1].start )
st.pop();
else if( str[i] == ar[2].close && st.top() == ar[2].start )
st.pop();
else
break;
}
//cout << st.size();
//cout << char(st.top());
if ( st.empty())
cout << "True";
else
cout << "False";
}