링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42860
#include <string>
using namespace std;
int solution(string name) {
int answer = 0;
string joystick;
int n = name.size();
int move = n-1;
for(int i = 0; i < n; i++){
answer += min(name[i] - 'A', 'Z' - name[i] +1);
int index = i + 1;
while(index < n && name[index] == 'A') index ++;
int a = i;
int b = n - index;
move = min(move, min(2 * a + b, a + 2 * b));
}
answer += move;
return answer;
}