https://ide.codingblocks.com/s/364121 is giving wrong output for ((a+(b))+(c+d))
Redundant paranthesis in stack
print output for each test case in seprate line.
ur updated code ->
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
int main()
{
int t;
cin>>t;
for(int j=0;j<t;j++)
{
stack<char>s;
string str;
cin>>str;
int i=0;
for(i=0;i!=str.length();i++)
{
char ch=str[i];
if(ch==')')
{
if(s.top()=='(')
{
cout<<"Duplicate\n";
break;//added
// return 0; this will stop execution of program which we dont want becuase we have other test case as well
}
else
{
while(s.top()!='(')
{
s.pop();
}
s.pop();// u commented this
}
}
else
{
s.push(ch);
}
}
if(i==str.size())
cout<<"Not Duplicates\n";
}
}