/* 6 berry cat strawberry str snake aw R:strawberry 8 sensual o b movimiento mba un boooooooooooooooooooooooooooomba unmovimientosensual R:boooooooooooooooooooooooooooomba 3 happy birthday mike R:-1 */ #include <iostream> #include <fstream> #include <cstring> using namespace std; ifstream fin("words.in"); //cut s string from d string; return d int strcut(char *d, const char s[]) { char* temp=strstr(d,s); if(temp) { d[temp-d]=0; strcat(d, temp+strlen(s)); return 1; } return 0; } void strbsort(int n, char s[][101]) { int ok; do { ok=1; for(int i=1; i<n; i++) if(strlen(s[i])<strlen(s[i+1])) { ok=0; swap(s[i], s[i+1]); } } while(!ok); } void citire(int &n, char s[][101]) { fin>>n; for(int i=1; i<=n; i++) fin>>s[i]; } int main() { int n; char s[101][101]; citire(n, s); strbsort(n, s); for(int i=1; i<n; i++) { char str[101]; strcpy(str, s[i]); for(int j=i+1; str[0]!=0 && j<=n; j++) while(strcut(str, s[j])); if(str[0]==0) { cout<<s[i]; return 0; } } cout<<-1; return 0; }