forked from rituparna-ui/hacktorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicate_brackets.cpp
More file actions
45 lines (42 loc) · 857 Bytes
/
duplicate_brackets.cpp
File metadata and controls
45 lines (42 loc) · 857 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
cout<<"testcases\n";
int t;
cin>>t;
while(t--)
{
cout<<"Enter string\n";
string x;
cin>>x;
int i=0;
stack<char>st;
bool flag =1;
while(x[i]!='\0')
{
if(x[i]==')')
{
if(st.top()=='(')
{
cout<<"Duplicate brackets\n";
flag=0;
break;
}
else
{
while(st.top()!='(') //assumed that brackets are perfectly balanced
st.pop();
}
st.pop();
}
else
{
st.push(x[i]);
}
i++;
}
if(flag)
cout<<"No Duplicate brackets"<<endl;
}
}