Getting no answer

#include
#include
using namespace std;
string check(string s)
{
stack st;
for(int i=0;i<s.length();i++)
{
if(s[i]==’(’||s[i]==’{’||s[i]==’[’)
{
st.push(s[i]);
}
else
{
switch(s[i])
{
case β€˜)’:
if(st.empty()||st.top()!=’(’)
return β€œNO”;
st.pop();
break;
case β€˜}’:
if(st.empty()||st.top()!=’{’)
return β€œNO”;
st.pop();
break;
if(st.empty()||st.top()!=’[’)
return β€œNO”;
st.pop();
break;
}
}
}
return s.empty()?β€œYES”:β€œNO”;
}
int main() {
string s;
cin>>s;
check(s);
return 0;
}
My code gets compiled successfully but is not givinfg answer.Can u please find the mistake.

@Hk199977 please save your code on cb.lk/ide and share link of your code.

@Hk199977

  • Line 35: What are you supposed to do with the return value of your function?
  • Line 30: Why are you returning β€œs.empty()”?
  • Line 24: Where is the default case of your switch?

But the same problem was on hackerrank.I used the same code for that.It worked there but not working on CB IDE

Can u please correct my mistake in the code.

@Hk199977,
I can but that would benefit absolutely no one, I have actually tried submitting the above code after making the changes I recommended and it works just fine.
Try debugging them given the exact locations of the bugs, and don’t pay much attention to results of other platforms, if there’s a WA, there’s a bug, just find it.
BTW one more heads up, You aren’t handling switch cases well, you are not using β€˜break’ statement, despite the given cases being mutually exclusive.