-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathte.cpp
More file actions
36 lines (35 loc) · 737 Bytes
/
Copy pathte.cpp
File metadata and controls
36 lines (35 loc) · 737 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
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int minTimeToType(string w) {
int ans = 0;
int now = 0;
for(int i=0;i<w.size();i++) {
int k=w[i]-'a';
if(k!=now) {
ans += min (abs(k-now), min(26+k-now, 26+now-k));
now = k;
}
ans+=1;
// cout<<ans<<" ";
}
// cout<<ans<<endl;
return ans;
}
int main()
{
minTimeToType("abc");
minTimeToType("bza");
minTimeToType("zjpc");
return 0;
}