Here is my code,
#include
#include
#include
using namespace std;
bool redPar(string str){
stack st;
bool flag = false;
for(int i =0; i< str.length(); i++){
char ch = str.at(i);
if(ch != ‘)’){
st.push(ch);
}else{
int counter = 0;
while(st.top()!=’(’){
st.pop();
counter++;
}
st.pop();
// cout<<counter<<"\n";
if(counter== 0){
flag = true;
return flag;
}
}
}
return flag;
}
int main() {
int t; cin>>t;
for(int i =0; i<t; i++){
string str;
getline(cin,str);
bool flag = redPar(str);
if(flag) cout<<"Duplicate\n";
else cout<<"Not Duplicates\n";
}
return 0;
}