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

5708번 - Code Lock 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB1622100.000%

문제

A lock you use has a code system to be opened instead of a key. The lock contains a sequence of wheels. Each wheel has the 26 letters of the English alphabet ‘a’ through ‘z’, in order. If you move a wheel up, the letter it shows changes to the next letter in the English alphabet (if it was showing the last letter ‘z’, then it changes to ‘a’). If you move the wheel down, it changes to show the previous letter in the English alphabet (if it was showing ‘a’, then it changes to ‘z’).

It is also possible to move any subsequence of contiguous wheels in the same direction with only one movement. This has the same effect of moving each of the wheels within the subsequence on that direction, but saves the effort of doing that one wheel at a time.

The lock opens when the wheels show a secret sequence of letters. Currently all wheels are showing the letter ‘a’. You want to know the minimum number of movements you need to open the lock.

입력

The input has several test cases. Each of them is given in exactly one line containing a nonempty string of at most 1000 lowercase letters. The string represents the secret sequence of letters that opens the lock.

The last test case is followed by a line containing a single asterisk.

출력

For each test case, output a line containing a single integer with the minimum number of movements to open the lock.

제한

예제 입력 1

abcxyz
abcdefghijklmnopqrstuvwxyz
aaaaaaaaa
zzzzzzzzz
zzzzbzzzz
*

예제 출력 1

5
25
0
1
3

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2009 C번

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

출처

대학교 대회

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

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