No.150 "Good Problem" (I didn't say it was a good problem
Problem Statement
You are given T strings. Line $i+1( 1 \le i \le T )$ contains the string Si.
When searching the string $Si$ from its beginning, if the substring good is found and, after that, the substring problem is found, the string $S_i$ is called a good problem.
If they are not found at all, the string $S_i$ is not a good problem.
You repeatedly perform the operation of rewriting one character at any position in the string $S_i$ to any of ’a’ to ’z’.
Let $K_i$ be the minimum number of operations required to make the string Si a good problem. Print $K_i$ on line $i$.
Input
T S1 … ST
$1 \le T \le 100$
$11 \le Sの長さ \le 100$
All characters in S are one of ’a’ to ‘z’.
Output
Print $K_i$ on line $i$. (The first line of output is line 1.)
Print a newline at the end.
Sample
Sample 1
Input
3 veryverygoodproblem goodexcellentproblems problemgood
Output
0 0 10
In this sample input,
S1 = "veryverygoodproblem"
S2 = "goodexcellentproblems"
S3 = "problemgood"
Then:
S1 is a good problem from the start.
S2 is also a good problem from the start.
S3 becomes a good problem by modifying the characters other than the 3rd character ('o') to get S3="goodproblem".
Therefore, K1 = 0, K2 = 0, K3 = 10.
Sample 2
Input
2 goodproblem agdddekproblemsdl
Output
0 2
Final strings (good problems) that minimize the number of operations include the following.
S1 = "goodproblem"
S2 = "agoodekproblemsdl
Note that there may be multiple final strings (good problems) reachable with the same number of operations.
Sample 3
Input
9 geodaaaproblem goodproblen badendlessprobrem podpdpprrobleem problemgoodprobremgood smallproblem proproprefurohobbyhobby gooeproblemd itisproblemcoolgoodproblem
Output
1 1 4 5 1 4 8 1 0
Sample 4
Input
5 problemgoodproblem problemproblem goodgoodgood xxxxxxxxxxxxx badendlessproblemactivetogood
Output
0 3 6 11 3
These test cases were added after the live stream ended.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
startcpp