The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he sees a snake first, it'll be its Head, and hence he will mark a 'H'. The snakes are long, and when he sees the snake finally slither away, he'll mark a 'T' to denote its tail. In the time in between, when the snake is moving past him, or the time between one snake and the next snake, he marks with '.'s.
Because the snakes come in a procession, and one by one, a valid report would be something like "..H..T...HTH....T.", or "...", or "HT", whereas "T...H..H.T", "H..T..H", "H..H..T..T" would be invalid reports (See explanations at the bottom).
Formally, a snake is represented by a 'H' followed by some (possibly zero) '.'s, and then a 'T'. A valid report is one such that it begins with a (possibly zero length) string of '.'s, and then some (possibly zero) snakes between which there can be some '.'s, and then finally ends with some (possibly zero) '.'s.
Chef had binged on the festival food and had been very drowsy. So his report might be invalid. You need to help him find out if his report is valid or not.
Input
The first line contains a single integer, R, which denotes the number of reports to be checked. The description of each report follows after this.
The first line of each report contains a single integer, L, the length of that report.
The second line of each report contains a string of length L. The string contains only the characters '.', 'H', and 'T'.
Output
For each report, output the string "Valid" or "Invalid" in a new line, depending on whether it was a valid report or not.
Constraints
1 ≤ R ≤ 500
1 ≤ length of each report ≤ 500
Example
Input:
6
18
..H..T...HTH....T.
3
...
10
H..H..T..T
2
HT
11
.T...H..H.T
7
H..T..H
Output:
Valid
Valid
Invalid
Valid
Invalid
Invalid
Explanation
"H..H..T..T" is invalid because the second snake starts before the first snake ends, which is not allowed.
".T...H..H.T" is invalid because it has a 'T' before a 'H'. A tail can come only after its head.
"H..T..H" is invalid because the last 'H' does not have a corresponding 'T'.
Full Answer in any programming language!!!
Answers
Answered by
0
const fi=''; fo=''; var f,g:text; n,i,m,k,t:integer; s:ansistring; valid:boolean; begin assign(f,fi);reset(f); assign(g,fo);rewrite(g); readln(f,n); for i:=1 to n do begin readln(f,m); readln(f,s); t:=0; valid:=true; for k:=1 to m do begin if s[k]='H' then inc(t); if s[k]='T' then dec(t); if (t<0) or (t>1) then begin valid:=false; break; end; end; if valid and (t=0) then writeln(g,'Valid') else writeln(g,'Invalid'); end; close(f);close(g);end
Answered by
2
if race = 1 x1 = .75.
if any(race,2,3,4) x1 = -.25.
if race = 2 x2 = .75.
if any(race,1,3,4) x2 = -.25.
if race = 3 x3 = .75.
if any(race,1,2,4) x3 = -.25.
execute.regression
/dependent = write
/method = enter x1 x2 x3.
< output omitted >
glm write by race /lmatrix "group 1 versus group 4" race 1 0 0 -1 /lmatrix "group 2 versus group 4" race 0 1 0 -1 /lmatrix "group 3 versus group 4" race 0 0 1 -1.
if race = 1 x1 = 1. if any(race,2,3) x1 = 0. if race = 4 x1 = -1. if race = 2 x2 = 1. if any(race,1,3) x2 = 0. if race = 4 x2 = -1. if race = 3 x3 = 1. if any(race,1,2) x3 = 0. if race = 4 x3 = -1. execute. regression /dep write /method = enter x1 x2 x3.< output omitted >
Method 2:
glm write by race /lmatrix "group 1 versus groups 1 2 and 3" race .75 -.25 -.25 -.25 /lmatrix "group 2 versus groups 1 3 and 4" race -.25 .75 -.25 -.25 /lmatrix "group 3 versus groups 1 2 and 4" race -.25 -.25 .75 -.25.Similar questions
Social Sciences,
7 months ago
Physics,
7 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
Biology,
1 year ago