Skip to content

Instantly share code, notes, and snippets.

@yssharma
Created October 16, 2016 11:41
Show Gist options
  • Save yssharma/7fd4342a75e614239f89ede6ab0480d8 to your computer and use it in GitHub Desktop.
Save yssharma/7fd4342a75e614239f89ede6ab0480d8 to your computer and use it in GitHub Desktop.
Codeforces 376 Div 2
package codeforces.x376;
import java.util.Scanner;
/**
* Created by ysharma on 10/16/16.
*/
public class A {
public static void main(String[] args) {
new A().doit();
}
private void doit(){
Scanner sc = new Scanner(System.in);
String name = sc.next();
char last = 'a';
int res = 0;
for(char ch : name.toCharArray()){
res += Math.min(Math.abs(last - ch), 26 - Math.abs(last - ch));
last = ch;
}
System.out.println(res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment