A. Night at the Museum

import java.util.Scanner;
public class NightattheMuseum {
public static int distance(char start, char end) {
return Math.min(Math.abs(start - end), Math.abs(26 - Math.abs(start - end)));
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String data = in.nextLine();
int rotations = 0;
rotations += distance('a', data.charAt(0));
for (int i = 0; i < data.length() - 1; i++) {
rotations += distance(data.charAt(i), data.charAt(i + 1));
}
System.out.println(rotations);
}
}

### Like this:

Like Loading...

*Related*