8 #define HASH_SIZE 16384
10 typedef unsigned char byte;
18 struct word *htab[HASH_SIZE];
21 /* 0 1 2 3 4 5 6 7 8 9 */
22 byte *n2c[10] = { "OQZ", "IJ", "ABC", "DEF", "GH", "KL", "MN", "PRS", "TUV", "WXY" };
31 for(c=n2c[i]; *c; c++)
34 c2n[tolower(*c)] = '0'+i;
40 unsigned int hash(byte *x, int len)
45 h = h * 13337 + c2n[*x++];
46 return h & (HASH_SIZE - 1);
55 while (fgets(l, sizeof(l)-1, f))
57 byte *z = strchr(l, '\n');
62 w = malloc(sizeof(struct word) + s);
74 printf("Scanned %d words.\n", c);
77 struct word *find(byte *x, int l)
80 struct word *w = htab[h];
89 while (ll && *p++ == c2n[*q++])
101 struct word *last[MAXL];
120 void sentence(byte *z)
128 printf("TOO LONG.\n");
137 if (best[j] >= 0 && (w = find(z+j, i-j)) && (best[i] < 0 || best[i] > best[j] + 1))
140 best[i] = best[j] + 1;
144 printf("NO SOLUTION.");
150 int main(int argc, char **argv)
155 if (!(f = fopen("voc", "r")))
157 perror("Unable to open vocabulary");
163 while (fgets(l, sizeof(l), stdin) && (k = strchr(l, '\n')))