그냥 시키는대로 구현 하면 되었다.
#include <string>
#include <algorithm>
using namespace std;
int solution(string name)
{
int answer = 0;
int shift = name.length() - 1;
for (int i = 0; i < name.length(); i++)
{
if (name[i] == 'A')
{
int target = i;
while (target < name.length() && name[target] == 'A')
target += 1;
int left = i == 0 ? 0 : i - 1;
int right = name.length() - target;
shift = min(shift, left + right + min(left, right));
}
}
answer += shift;
for (auto c : name)
answer += min(c - 'A', 'Z' - c + 1);
return answer;
}
'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 예상 대진표 (0) | 2022.05.24 |
|---|---|
| [프로그래머스] (C++) LV2 게임 맵 최단거리 (0) | 2022.05.24 |
| [프로그래머스] (C++) LV2 소수 찾기 (0) | 2022.05.23 |
| [프로그래머스] (C++) LV2 가장 큰 수 (0) | 2022.05.22 |
| [프로그래머스] (C++) LV2 프린터 (0) | 2022.05.22 |