-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3663.cpp
47 lines (45 loc) · 864 Bytes
/
3663.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 3663. 고득점
// 2019.06.03
// 그리디 알고리즘
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin >> t;
while (t > 0)
{
t--;
string name;
cin >> name;
int ans = 0;
int move = name.size() - 1;
for (int i = 0; i < name.size(); i++)
{
int next = i + 1;
char target = name[i];
if (target <= 'N')
{
ans += target - 'A';
}
else
{
ans += 'Z' - target + 1;
}
// 글자가 A인 경우 next를 1 증가
while (next < name.size() && name[next] == 'A')
{
next++;
}
// 현재 위치에서 좌,우 중 작은 수 찾기(i, name.size()-next)
// 둘 중 작은 거리 * 2 + 긴 거리
int move2 = i + name.size() - next + min(i, (int)name.size() - next);
move = min(move, move2);
}
ans += move;
cout << ans << endl;
}
return 0;
}