# Include <iostream>
# Include <stdio. h> # include <string. h> # include <vector> # include <list> # include <math. h ># include <algorithm> using namespace STD; int main () {char DIC [1001] [21], substr [21], TMP [21]; int I, j, p, K; memset (DIC, 0, sizeof (char) * 1001*21); memset (substr, 0, sizeof (char) * 21); memset (TMP, 0, sizeof (char) * 21); k = 0; while (EOF! = Scanf ("% s", DIC [k]) K ++; for (I = 0; I <K; I ++) {for (j = 1; j <= strlen (DIC [I]); j ++) {strncpy (substr, DIC [I], J); For (P = 0; P <K; P ++) {If (P! = I) {strncpy (TMP, DIC [p], J); If (strcmp (TMP, substr) = 0) Break ;}} if (P <k) continue; if (P = k) break;} printf ("% S % s \ n", DIC [I], substr); memset (substr, 0, sizeof (char) * 21); memset (TMP, 0, sizeof (char) * 21);} return 1 ;}
The time complexity is 1000*20*1000. You can use the Prefix Tree (Dictionary tree)
Brute force thinking:
For each string, the prefix with the length of J (1 <= j <= strlen) is used to determine whether the prefix exists in other strings. If not, the minimum prefix of the string;
When J is equal to the length of the string, it can be output directly without being determined by other strings.