#include
#include
using namespace std;
bool checkexpression(string str)
{
stacks;
for(int i=0;i<str.size();i++)
{
char curchar=str[i];
if(curchar==β(β)
{
s.push(curchar);
}
else if(curchar==β)β)
{
if(s.empty() || s.top()!=β(β){
return false;
}
s.pop();
}
}
return s.empty();
}
int main() {
string expr;
cin>>expr;
bool isvalid=checkexpression(expr);
if(isvalid)
{
cout<<βYesβ;
}
else{
cout<<βNoβ;
}
return 0;
}
What is wrong with the code
hi @Kunalgoyal, please send your code using any online ide , due to some formatting some part of code are missing , you can use https://ide.codingblocks.com/
@Kunalgoyal, in your solution you are only considering () but in the question it is mentioned that the input can have β{β, β}β , β(β , β)β, β[β , β]β types of parenthesis too
got it now. thanks for your help
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.