Untitled
........................unknown
c_cpp
3 years ago
1.3 kB
9
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...