#include <stdio.h>
#include <string.h>
char table [1024][1024];
int strnmcmp (char *src, char *des, int m, int n) {
int i, j;
for (i = m, j = 0; i <= n; i++, j++)
if (src [j] != des [i])
return -1;
return 0;
}
// strncat (p, src+m, n-m);
int main (void) {
int ch;
int i, j, k, n, length, notice;
int c;
char text [] = "ABBACABABB";
int coded [256*128];
int x;
for (n = 'A' - 'A'; n < ('C' - 'A')+1; n++) {
table [n][0] = n + 'A';
table [n][1] = 0;
}
for (i = 0, x = 0, j = 1, length = 1; i < strlen (text)+1; ) {
for (length = 1; (i + length) < strlen (text)+1; ) {
for (k = 0; (k < n) \&\& (strncmp (table [k], text+i, length) != 0); k++);
if (k >= n) {
coded [x] = notice;
x++;
strncpy (table [n], text+i, length);
n++;
length--;
break;
}
else if (k < n) {
notice = k;
length++;
}
}
i = i + length;
}
for (i = 0; i < x; i++)
printf ("%s", table[coded[i]]);
return 0;
}