-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Night_at_the_Museum.cpp
More file actions
37 lines (30 loc) · 906 Bytes
/
A_Night_at_the_Museum.cpp
File metadata and controls
37 lines (30 loc) · 906 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
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <ios>
#include <iostream>
#include <iterator>
#include <ostream>
#include <shared_mutex>
#include <utility>
#include <vector>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<int> alphabet(26);
string exhibit;
cin >> exhibit;
int rotations = 0;
char next = 'a';
// distance between points x and y on the circle of length l (26 in our case) is min(|x - y|, l - |x - y|)
for(auto& ch : exhibit){
// cout << ch << " " << ch - 'a' + 1<< endl;
// cout << abs((ch - 'a') - (next - 'a')) << " " << (26 - abs((ch - 'a') - (next - 'a'))) << endl;
rotations += min(abs((next - 'a') - (ch - 'a')), (26 - abs((next - 'a') - (ch - 'a'))));
next = ch;
}
cout << rotations << endl;
return 0;
}