char *s = "kvkkvkvkkvkkk"; char *m[15] = { "v", "kv", "vk", "kvk", "kkvk", "kvkk", "kkvkk", "kkkvkk", "kkvkkk", "vkk", "kkv", "kvkkk", "kkkvk", "vkkk", "kkkv" }; int found[30]; int d = 0; void match(s) char *s; { if (*s == '\0') { int i; for (i = 0; i < d; i++) printf("%s ", m[found[i]]); printf("\n"); } else { int i; for (i = 0; i < 15; i++) if (!strncmp(s, m[i], strlen(m[i]))) { found[d++] = i; match(s + strlen(m[i])); d--; } } } void main() { match(s); }