-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLv2_조이스틱.cpp
More file actions
46 lines (42 loc) · 753 Bytes
/
Lv2_조이스틱.cpp
File metadata and controls
46 lines (42 loc) · 753 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
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int solution(string name) {
int answer = 0;
int answer1 = 0;
int c1 = 0;
int answer2 = 0;
int c2 = 0;
int size = name.length();
for (int i = 0; i < size; i++) {
int temp = name[i] - 'A';
if (name[i] == 'A')
c1++;
else c1 = 0;
if (temp > 13)
temp = 26 - temp;
answer1 += temp;
answer1++;
}
answer1--;
answer1 -= c1;
answer2 += name[0] - 'A';
answer2++;
for (int i = size - 1; i > 0; i--) {
int temp = name[i] - 'A';
if (name[i] == 'A')
c2++;
else
c2 = 0;
if (temp > 13)
temp = 26 - temp;
answer2 += temp;
answer2++;
}
answer2--;
answer2 -= c2;
answer = min(answer1, answer2);
return answer;
}