Can any one tell me whats wrong with this code matching brakets stack

#include
using namespace std;
int main()
{
int tc;
cin>>tc;
while(tc–)
{
string s;
cin>>s;
int size=s.length();
char stack[100];
int top=-1,ans=0;
for(int i=0;i<size;i++)
{
if(s[i]==’(’||s[i]==’[’||s[i]==’{’)
{
top++;
stack[top]=s[i];
}
else if(s[i]==’)’||s[i]==’]’||s[i]==’}’)
{
char b=stack[top];
if(b==s[i])
{
top–;
}
else
{
break;
}
}
}
if(top==-1)
{
cout<<“YES”<<endl;
}
else
{
cout<<“NO”<<endl;
}
}
return 0;

}

provide link to your code instead it will be more helpfull to debug.

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;
        }
    }
}

thanks i got it