Skip to content

조이스틱 #422

@fkdl0048

Description

@fkdl0048
#include <string>
#include <vector>

using namespace std;

int solution(string name) {
    int answer = 0;
    int n = name.length();
    int turn = n - 1;
    
    for (int i = 0; i < n; i++) {
        if (name[i] - 'A' < 14) answer += name[i] - 'A';
        else answer += 'Z' - name[i] + 1;
        
        int ind = i + 1;
        while (ind < n && name[ind] == 'A') ind++;
        turn = min(turn, i + n - ind + min(i, n - ind));
    }
    
    answer += turn;
    return answer;
}

Metadata

Metadata

Assignees

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions