Logo
(追記) (追記ここまで)

27563번 - Moo Operations 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB85739935048.209%

문제

Because Bessie is bored of playing with her usual text string where the only characters are 'C,' 'O,' and 'W,' Farmer John gave her $Q$ new strings (1ドル \leq Q \leq 100$), where the only characters are 'M' and 'O.' Bessie's favorite word out of the characters 'M' and 'O' is obviously "MOO," so she wants to turn each of the $Q$ strings into "MOO" using the following operations:

  1. Replace either the first or last character with its opposite (so that 'M' becomes 'O' and 'O' becomes 'M').
  2. Delete either the first or last character.

Unfortunately, Bessie is lazy and does not want to perform more operations than absolutely necessary. For each string, please help her determine the minimum number of operations necessary to form "MOO" or output $-1$ if this is impossible.

입력

The first line of input contains the value of $Q$.

The next $Q$ lines of input each consist of a string, each of its characters either 'M' or 'O'. Each string has at least 1 and at most 100 characters.

출력

Output the answer for each input string on a separate line.

제한

예제 입력 1

3
MOMMOM
MMO
MOO

예제 출력 1

4
-1
0

힌트

A sequence of 4ドル$ operations transforming the first string into "MOO" is as follows:

Replace the last character with O (operation 1)
Delete the first character (operation 2)
Delete the first character (operation 2)
Delete the first character (operation 2)

The second string cannot be transformed into "MOO." The third string is already "MOO," so no operations need to be performed.

출처

Olympiad > USA Computing Olympiad > 2022-2023 Season > USACO 2023 January Contest > Bronze 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /