Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Snake Procession codechef solution in c++

#include<iostream>
#define ll long long
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;

void solve()
{
	ll n;
	cin >> n;
	string ans;
	cin >> ans;
	stack<char> s;
	for (ll i = 0; i < n; i++)
	{
		if (ans[i] >= 65 && ans[i] <= 90)
		{
			if (s.empty())
			{
				s.push(ans[i]);
			}
			else
			{
				if (s.top() == 'H' && ans[i] == 'T')
				{
					s.pop();
				}
				else
				{
					break;
				}
			}
		}
	}
	if (s.empty())
	{
		cout << "Valid
";
	}
	else
	{
		cout << "Invalid
";
	}
}

int main()
{

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Snake #Procession #codechef #solution
ADD COMMENT
Topic
Name
3+3 =