7 struct pair
{ char x
; char y
; };
8 struct template { struct pair key
; char ins
; UT_hash_handle hh
; };
12 char *input
= NULL
, *buf
= NULL
, *oldinput
= NULL
;
13 size_t inputlen
= 0, len
;
14 struct template *template = NULL
;
16 if (getline(&input
, &inputlen
, stdin
) == -1)
18 while (getline(&buf
, &len
, stdin
) != -1) {
19 if (strcmp(buf
, "\n") == 0)
21 struct template *t
= calloc(1, sizeof(struct template));
25 HASH_ADD(hh
, template, key
, sizeof(struct pair
), t
);
28 for (int i
= 0; i
<20; i
++) {
31 input
= malloc(inputlen
*= 2);
34 for (c
= &oldinput
[0]; *c
!= '\0'; c
++) {
35 input
[inputlen
++] = *c
;
36 struct pair p
= {.x
=c
[0], .y
=c
[1]};
38 HASH_FIND(hh
, template, &p
, sizeof(struct pair
), t
);
40 input
[inputlen
++] = t
->ins
;
42 input
[inputlen
++] = '\0';
46 int mcommon
= 0, lcommon
= INT_MAX
;
47 for (char *c
= &input
[0]; *c
!= '\0'; *c
++) {
50 for (int i
= 0; i
<255; i
++) {
51 if (freq
[i
] > mcommon
)
53 if (freq
[i
] > 1 && freq
[i
] < lcommon
)
57 printf("%d\n", mcommon
-lcommon
);