-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathminimumKeypadClickCount.cpp
More file actions
36 lines (35 loc) · 1.01 KB
/
Copy pathminimumKeypadClickCount.cpp
File metadata and controls
36 lines (35 loc) · 1.01 KB
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
int minimumKeypadClickCount(string input)
{
char right[9][3] = {
{'a', 'j', 's'},
{'b', 'o', 't'},
{'c', 'p', 'u'},
{'d', 'k', 'v'},
{'h', 'm', 'z'},
{'g', 'l', '@'},
{'e', 'n', 'w'},
{'f', 'q', 'x'},
{'i', 'r', 'y'}};
int n, count1 = 0, count2 = 0;
n = input.length();
for (int i = 0; i < n; i++)
{
int d = input[i] - 97;
d = d % 3;
count1 += (d + 1);
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 9; j++)
{
for (int k = 0; k < 3; k++)
{
if (right[j][k] == input[i])
{
count2 += (k + 1);
}
}
}
}
return count2;
}