-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday60.cpp
43 lines (41 loc) · 968 Bytes
/
day60.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
#include<iostream>
#include<string>
#include<stack>
using namespace std;
bool cool(string &misaka)
{
stack<char> clues;
int count=0,i=0;
try{if(misaka.length()%2!=0)
throw 303;
while(i<misaka.length())
{
if(misaka[i]=='{'||misaka[i]=='['||misaka[i]=='(')
{
clues.push(misaka[i]);
}
if((misaka[i]=='}'&&clues.top()=='{')||(misaka[i]==']'&&clues.top()=='[')||(misaka[i]==')'&&clues.top()=='('))
clues.pop();
++i;
}
}
catch(int l)
{
cout<<"wrong input the statement should not consist of any other elemnet other than prantheses error "<<l<<endl;
exit(0);
}
if(clues.size()==0)
return true;
return false;
}
int main()
{
cin.tie(0);
string kiss;
cout<<"enter the string character to find if balanced or not(only parantases allowed(j\n";
cin>>kiss;
if(cool(kiss))
cout<<"balanced\n";
else
cout<<"not balances\n";
}