<code lang="cs">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<string> coll = new List<string>();
for (int i = 0; i < args.Length; i++)
{ coll.Add(args[i]); }
Genome GG = new Genome();
string s = GG.GetConcatGenom(coll);
Console.WriteLine(s);
Console.ReadKey();
//GetConcatGenom(coll);
}
}
public class Genome
{
public string GetConcatGenom(List<String> genoms)
{
List<string> sss = new List<string>();
foreach (var item in genoms)
{
List<string> newgen = new List<string>(genoms);
newgen.Remove(item);
string curres = ConcatRecursive(item, newgen);
sss.Add(curres);
//Console.WriteLine(curres);
}
return "OK";
}
public string ConcatRecursive(string s, List<String> genoms)
{
if (genoms.Count == 0)
{
return s;
}
for (int j = 0; j < genoms.Count; j++)
{
List<String> gens = new List<String>(genoms);
string newgen = s;
//if (genoms.Count == 0) { return newgen ; }
int minlen = Math.Min(genoms[j].Length, newgen.Length);
bool finded = false;
for (int i = minlen; i > 0; i--)
{
if (finded )
{
break;
}
if (newgen.EndsWith(genoms[j].Substring(0, i)))
{
finded = true;
newgen = newgen.Substring(0, newgen.Length - i);
newgen += genoms[j];
gens.Remove(genoms[j]);
if (gens.Count == 0)
{
return newgen;
}
else
{
string curres = ConcatRecursive(newgen, gens);
if (curres != "")
{
Console.WriteLine(curres);
}
}
}
}
}
return "";
}
}
}
</code>