Untitled

........................
Anonymous
c_cpp
10/05/2022 9:18 PM
1.7 KB
18
Indexable
void solution()
{
    ll t;
    cin >> t;
    w(t)
    {
        string s ;
        cin >> s;
        stack <char> st;
        if(s[0] == 'A')
        {
            st.push('A');
            for(ll i=1; i<sz(s); i++)
            {
                if(s[i] != 'A')
                {
                    st.pop();
                }
                else
                {
                    st.push('A');
                }
            }
        }
        else if(s[0] == 'B')
        {
            st.push('B');
            for(ll i=1; i<sz(s); i++)
            {
                if(s[i] != 'B')
                {
                    st.pop();
                }
                else
                {
                    st.push('B');
                }
            }
        }
        else if(s[0] == 'C')
        {
            st.push('C');
            for(ll i=1; i<sz(s); i++)
            {
                if(s[i] != 'C')
                {
                    st.pop();
                }
                else
                {
                    st.push('C');
                }
            }
        }

        if(st.empty())
        {
            cout << "True";
        }
        else 
        {
            cout << "False";
        }
    }
}
Editor is loading...