-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSnake Procession.cpp
More file actions
46 lines (43 loc) · 899 Bytes
/
Copy pathSnake Procession.cpp
File metadata and controls
46 lines (43 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
int main()
{
long int t;
cin>>t;
for(int i=0;i<t;i++)
{
int tail=0,head=0,n;
string xoxo;
cin>>n;
cin>>xoxo;
for(int f=0;f<n;f++)
{
if(xoxo[f]=='H')
head++;
if(xoxo[f]=='T')
tail++;
}
if(head!=tail)
cout<<"Invalid"<<endl;
else
{
head=0;
tail=0;
int valid=0;
for(int f=0;f<n;f++)
{
if(xoxo[f]=='H')
head++;
else if(xoxo[f]=='T')
tail++;
if(head==tail || head-tail==1)
valid++;
}
if(valid==n)
cout<<"Valid"<<endl;
else
cout<<"Invalid"<<endl;
}
}
return 0;
}