Search
 
SCRIPT & CODE EXAMPLE
 

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

PREVIOUS NEXT
Code Example
Cpp :: easy way to learn file handling in c++ array 
Cpp :: online compiler c++ with big O calculatorhttps://www.codegrepper.com/code-examples/cpp/how+to+convert+string+to+wchar_t+in+c%2B%2B 
Cpp :: 136. Single Number leetcode solution in c++ 
Cpp :: c++ konsolenausgabe 
Cpp :: how to replace a element in a vector c++ using index 
Cpp :: pcl c++ read .pcd 
Cpp :: c++ copy with transform 
Cpp :: esp8266 wifi.localip() to string 
Cpp :: C++ operation 
Cpp :: c++ How can I make a std::vector of function pointers 
Cpp :: github static std::string gen_name() { } // To do static int gen_number() { } // To do static int gen_grade() { } // To do double compute average() { } // To do 
Cpp :: query for rmq using sqrt decomposition 
Cpp :: lnk2001 unresolved external symbol __imp_PlaySoundA 
Cpp :: Remove the jth object from the subset 
Cpp :: c++ fps sleep while loop 
Cpp :: Int main ( ) { int i,n; cinn; i=n; while(i=1) { i=i+5; i=i-6; } } 
Cpp :: c++ operators 
Cpp :: show mouse c++ 
Cpp :: ++i v.s i++ 
Cpp :: permutation and combination program in c++ 
Cpp :: Lapindromes codechef solution in c++ 
Cpp :: remove element from vector c++ by index 
Cpp :: how to call subclass override method in c++ 
Cpp :: pointers in c++ 
Cpp :: default access specifier in c++ 
Cpp :: c++ quicksort 
Cpp :: c++ handling 
Cpp :: friend class c++ 
C :: terminal count files in directory 
C :: get_session` is not available when using TensorFlow 2.0. 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =