#include #include #include #include #include #include #include #include #include using namespace std; int n; char words[1001][1001]; char* theword; int maxim = 0; bool isPrefix(char* a, char* b) { if (strlen(b) > strlen(a)) return false; int p = strlen(b); for (int i = 0; i < p; i++) { if (a[i] != b[i]) return false; } return true; } bool verifyconcat(char* word, int index) { if (strlen(word) == 0) { return true; } int j; int poz = 0; for (j = 1; j <= n; j++) { if (index !=j && isPrefix(word, words[j])) { return verifyconcat(word + strlen(words[j]), index); } } return false; } int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); int i; cin >> n; for (i = 1; i <= n; i++) { cin >> words[i]; } for (i = 1; i <= n; i++) { if (verifyconcat(words[i], i)) { if (strlen(words[i]) > maxim) { maxim = strlen(words[i]); //strcpy_s(theword, 100, words[i]); theword = words[i]; } } } if (maxim != 0) { cout << theword; } else cout << -1; return 0; }