-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path570.cpp
More file actions
56 lines (50 loc) · 1017 Bytes
/
Copy path570.cpp
File metadata and controls
56 lines (50 loc) · 1017 Bytes
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
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int cnt;
int l[1000];
int r[1000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
int len = str.length();
int sum = 0;
for (int j = 0; j < len; j++) {
if (str[j] <= 'N') {
sum += (str[j] - 'A');
}
else {
sum += 26 - (str[j] - 'A');
}
}
bool currentA = false;
cnt = 0;
for (int j = 1; j < len; j++) {
if (!currentA && str[j] == 'A') {
l[cnt] = j - 1;
currentA = true;
}
if (currentA && str[j] != 'A') {
r[cnt++] = j;
currentA = false;
}
if (currentA && j == len - 1) {
r[cnt++] = j + 1;
currentA = false;
}
}
int ans = sum + len - 1;
//cout << cnt << endl;
for (int j = 0; j < cnt; j++)
{
//cout << sum + l[j] * 2 + len - r[j] << " " << sum + (len - r[j]) * 2 + l[j] << endl;
ans = min(ans, min(sum + l[j] * 2 + len - r[j], sum + (len - r[j]) * 2 + l[j]));
}
cout << ans << endl;
}
return 0;
}