Problem 1 : what is this you are including nothing.
Problem 2 : tc- is not an shorthand operator in c++ it’s tc-- or just do tc -= 1 and correct it all over.
Problem 3 : I would say this is not correct (at all). Just follow the simple approach when ever the closing parenthesis appears you should have it’s starting parenthesis.
I doubt what you actually trying to do here. first of all there are three types of parenthesis so how could you just do that.
Finally, please look into below code i made and understand the concept.
#include <bits/stdc++.h>
using namespace std;
signed main()
{
// taking test cases input
int test; cin >> test;
cin.ignore(); // flushing input buffer
while(test--)
{
// taking string input
string s; cin >> s;
stack<char> Stack;
// looping through string to find out the answer
for( auto i = 0 ; i < s.length() ; ++i ){
// if opening parenthesis [ or { or (
if( s[i] == '{' || s[i] == '[' || s[i] == '(' ){
Stack.push(s[i]);
}
// if closing parenthesis } or ] or )
else if ( s[i] == '}' || s[i] == ']' || s[i] == ')' ){
if(!Stack.empty()) // checking if stack is not empty
{
if ( (Stack.top() == '{' && s[i] == '}') || (Stack.top() == '[' && s[i] == ']' ) || (Stack.top() == '(' && s[i] == ')' )){
// Stack is balanced remove the opening parenthesis from Stack
Stack.pop();
}
else{
// Stack is not balanced break loop and answer no.
break;
}
}
else{
Stack.push(s[i]);
}
}
}
if( Stack.empty() == true ){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
}