#include #include int suffix_is_prefix(const char * w, int total_length, int prefix_length) { assert(prefix_length < total_length); int i; for (i = 0; i < prefix_length; ++i) if (w[i] != w[i + (total_length - prefix_length)]) return 0; return 1; } int main(int argc, char * argv[]) { const char * w = argv[1]; int pos = 0; int c; while (w[pos] != 0 && (c = getchar()) != EOF) { while (c != w[pos] && pos > 0) { int j; for (j = pos - 1; j > 0; --j) if (suffix_is_prefix(w, pos, j)) break; pos = j; } if (c == w[pos]) ++pos; } return (w[pos] == 0) ? 0 : 1; }