-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_bracket.cpp
More file actions
80 lines (77 loc) · 1.32 KB
/
stack_bracket.cpp
File metadata and controls
80 lines (77 loc) · 1.32 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
int contents[100];
int top=-1;
void make_empty(void)
{
top=-1;
}
bool isempty(void)
{
return top==-1;
}
bool is_full(void)
{
return top==100;
}
void push(int i)
{
if(!is_full())
contents[++top]=i;
}
int pop(void)
{
if(!isempty())
return contents[top--];
}
int main()
{
char example[100];
cin>>example;
int i;
for(i=0;example[i]!='\0';i++)
{
if(example[i]=='{')
push(1);
else if(example[i]=='(')
push(2);
else if(example[i]=='[')
push(3);
else if(example[i]=='}')
{
if(contents[top]==1)
pop();
else break;
}
else if(example[i]==')')
{
if(contents[top]==2)
pop();
else break;
}
else if(example[i]==']')
{
if(contents[top]==3)
pop();
else break;
}
}
if(top==-1) cout<<"yes\n";
else cout<<"no\n";
system("pause");
return 0;
}