about summary refs log tree commit diff
path: root/ntu/writer.c
blob: 322799144fdce91a7867484121cb8b057101cb42 (plain) (blame)
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
#include <stdio.h>
#include <string.h>

typedef char *string;

const string KEYBOARD[10] = {"_0", ".,?!1", "abc2", "def3", "ghi4", "jkl5",
                             "mno6", "pqrs7", "tuv8", "wxyz9"};
struct Foo {
	char num;
	char times;
};

struct Foo get(char letter)
{
	struct Foo val;
	char len;

	for (val.num = 0; val.num < 10; val.num++) {
		len = strlen(KEYBOARD[val.num]);
		for (val.times = 0; val.times < len; val.times++)
			if (KEYBOARD[val.num][val.times] == letter) {
				val.times++;
				return val;
			}
	}
}

int main()
{
	char t, i, s[50][1000];

	scanf("%hhd", &t);
	for (i = 0; i < t; i++)
		scanf("%s", s[i]);

	short time, j;
	struct Foo f00;
	char olechr;

	for (i = 0; i < t; i++) {
		time = 0;
		olechr = 1;
		for (j = 0; j < strlen(s[i]); j++) {
			f00 = get(s[i][j]);
			time += f00.times;
			if (f00.num != olechr)
				time++;
			olechr = f00.num;
		}
		printf("%hd\n", time);
	}
}