Another FizzBuzz Task
Time limit2sMemory limit512 MB
Given a string L of digits and Fizz/Buzz letters, find the 1-based position where L first appears in the infinite FizzBuzz string, or report -1.
- Level
Medium7 of 10
- Topics
- String matching, Number theory, Math
- Solved
- No attempts yet
Statement
Transform the sequence of positive integers as follows:
- If an integer is divisible by 15, replace it with "
FizzBuzz". - If an integer is divisible by 3 and has not been replaced yet, replace it with "
Fizz". - If an integer is divisible by 5 and has not been replaced yet, replace it with "
Buzz". - Otherwise, leave the integer unchanged.
The beginning of the sequence is as follows:
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz ...
Let be the infinite string obtained by writing this sequence without spaces. Given a string , determine whether appears as a substring of . If it does, find the 1-based index of its first appearance.
Input
The first line contains one integer , the number of test cases (). Each of the next lines contains one non-empty string made of digits and the letters "F", "B", "i", "u", and "z". The length of does not exceed 15.
Output
For each test case, print if does not appear in . Otherwise, print the smallest 1-based index of the first element of in .