-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid.txt
67 lines (50 loc) · 1.34 KB
/
valid.txt
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vi vector<int>
#define vll vector<long long>
#define mp make_pair
#define MPII map<int,int>
#define MPLL map<long long,long long>
#define MPSI map<string,int>
#define MPIS map<int,string>
#define PRII pair<int,int>
#define PRLL pair<long long,long long>
#define SP cout<<fixed<<setprecision(10);
#define rep(i,inval,n) for(int i = inval; i < n; i++)
#define all(x) x.begin(),x.end()
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
int main()
{
IOS;
int t=1;
// cin>>t;
while(t--)
{
int top=-1;
char stk[100];
string str; cin>>str;
for(int i=0;i<str.size();i++)
{
if(str[i]=='(' || str[i]=='{' || str[i]=='[')
{
top++;
stk[top]=str[i];
}
else{
char temp=stk[top];
top--;
if((temp=='(' && str[i]!=')' )|| (temp=='{' && str[i]!='}') || (temp=='['&& str[i]!=']' ) )
break;
}
}
if(top==-1) cout<<"Balanced"<<endl;
else cout<<"Imbalanced"<<endl;
}
return 0;
}