• + 0 comments

    C++: its run correctly in my compiler but when i run it on hackerrank it shows me that all test cases are wrong, and i try all of the test cases and it run correct on my compiler, i dont know what to do!!

    #include<bits/stdc++.h>
    using namespace std;
    void fastIO()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    }
    int main()
    {
        fastIO();
        int t;
        cin >> t;
        cin.ignore();
        
        while (t--) {
            stack<char>st;
            bool balanced= 1;
            string line;
            getline(cin, line);
            
            for (int i = 0; i < line.length(); i++)
            {
                if(line[i]=='('||line[i]=='{'||line[i]=='[') {
                    st.push(line[i]);
                }
                else if(line[i]==')'||line[i]=='}'||line[i]==']')
                {
                    if(!st.empty())
                    {
                        if(line[i]==')'&&st.top()=='(')st.pop();
                        else if(line[i]==']'&&st.top()=='[')st.pop();
                        else if(line[i]=='}'&&st.top()=='{')st.pop();
                        else {
                            
                            balanced=0;
                            break; 
                        }
                    }
                }
            }
            
            if(balanced==0||!st.empty()){
                cout<<"No"<<"\n";
                balanced=1;
            }
            else cout<<"Yes"<<"\n";
            
        }
        return 0;
    }
            
        }
        return 0;
    }