A. Night at the Museum

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);
	}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s