-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP11530.cpp
69 lines (64 loc) · 1.05 KB
/
P11530.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <stdio.h>
int countKeypressesForChar(char c) {
switch(c) {
case 'a':
case 'd':
case 'g':
case 'j':
case 'm':
case 'p':
case 't':
case 'w':
case ' ':
return 1;
case 'b':
case 'e':
case 'h':
case 'k':
case 'n':
case 'q':
case 'u':
case 'x':
return 2;
case 'c':
case 'f':
case 'i':
case 'l':
case 'o':
case 'r':
case 'v':
case 'y':
return 3;
default:
return 4;
}
}
int countKeypressesForWord(char *s) {
int sum = 0;
char c;
for(int i = 0; isprint(c = s[i]); ++i) {
sum += countKeypressesForChar(c);
}
return sum;
}
unsigned int readUInt() {
unsigned int ret = 0;
char w[20];
gets(w);
for(int i = 0; i < 20; ++i) {
if(!(w[i] >= '0' && w[i] <= '9'))
break;
ret = ret * 10 + (w[i]-'0');
}
return ret;
}
int main() {
char w[109];
unsigned int cases = readUInt();
for(unsigned int cas = 1; cas <= cases; ++cas) {
gets(w);
std::cout << "Case #" << cas << ": " << countKeypressesForWord(w) << std::endl;
}
return 0;
}