/*题意是将文件还原。n分文件摔成了2*n份,其中每一对都对应一份源文件。求原文件。
这题的写法充分展示了c++的优势,其中的string【n】的用法,和定义的string排序。
从中间分开,前后进行搜索。*/
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
string s[270];
string tmp;
bool vis[270];
bool cmp(string a,string b)
{
return a.length()>b.length();
}
int h;
bool judge(string a)
{
for(int i=0;i<(h+1)>>1;i++)
{
bool flag=false;
vis[i]=true;
for(int j=h-1;j>i;j--)
{
if(!vis[j]&&s[i]+s[j]==a)
{
vis[j]=true;
flag=true;
break;
}
}
if(!flag) return false;
}
return true;
}
int main()
{
char ss[270];
while(gets(ss))
{
s[0]=ss;
h=1;
while(gets(ss))
{
if(ss[0]=='\0') break;
s[h++]=ss;
}
sort(s,s+h,cmp);
bool found=false;
for(int i=h-1;i>=0&&s[i].length()==s[h-1].length();i--)
{
tmp=s[0]+s[i];
memset(vis,false,sizeof(vis));
if(judge(tmp))
{
found=true;
cout << tmp << endl;
break;
}
}
if(!found) cout << s[0]+s[h-1] << endl;
}
return 0;
}