Coin Game
InterviewTime limit1sMemory limit128 MB
Count occurrences of each of 8 possible length-3 head/tail patterns among all consecutive triples in a 40-character coin toss string, for multiple test cases.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
In this coin game, several players each choose one length-3 coin sequence. A 3-coin sequence is a length-3 sequence made of heads and tails. There are eight possible sequences: TTT, TTH, THT, THH, HTT, HTH, HHT, and HHH.
A judge tosses one coin 40 times and records the outcomes in order. From the recorded string, consider every consecutive block of three tosses and count how many times each 3-coin sequence appears. The player who chose the most frequent sequence wins.
Given the result of 40 coin tosses, compute the number of appearances of each 3-coin sequence. If all 40 tosses are H, then HHH appears 38 times.
Input
The first line contains the number of test cases P(1 ≤ P ≤ 1000). Each test case consists of one line containing the result of 40 coin tosses. Heads is written as H, and tails is written as T.
Output
For each test case, output how many times each 3-coin sequence appears. Print the counts in the order TTT, TTH, THT, THH, HTT, HTH, HHT, HHH, separated by spaces.