using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
string[] x = new[] { "10111", "10122", "10250", "10113" };
var allSubstrings = new Dictionary<int, List<string>>();
for (int i = 0; i < x.Length; i++)
{
var substrings = new List<string>();
string str = x[i];
for (int c = 0; c < str.Length - 1; c++)
{
for (int cc = 1; c + cc <= str.Length; cc++)
{
string substr = str.Substring(c, cc);
if (allSubstrings.Count < 1 || allSubstrings[allSubstrings.Count - 1].Contains(substr))
substrings.Add(substr);
}
}
allSubstrings.Add(i, substrings);
}
if (allSubstrings[allSubstrings.Count - 1].Count > 0)
{
string mostCommon = allSubstrings[allSubstrings.Count - 1]
.GroupBy(str => str)
.OrderByDescending(g => g.Key.Length)
.ThenByDescending(g => g.Count())
.First().Key;
for (int i = 0; i < x.Length; i++)
x[i] = x[i].Replace(mostCommon, "");
}
foreach(string str in x)
Console.WriteLine(str);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uR2xvYmFsaXphdGlvbjsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwoKcHVibGljIGNsYXNzIFRlc3QKewogICAgCgoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewogICAgICAgIHN0cmluZ1tdIHggPSBuZXdbXSB7ICIxMDExMSIsICIxMDEyMiIsICIxMDI1MCIsICIxMDExMyIgfTsKCQl2YXIgYWxsU3Vic3RyaW5ncyA9IG5ldyBEaWN0aW9uYXJ5PGludCwgTGlzdDxzdHJpbmc+PigpOwoJCWZvciAoaW50IGkgPSAwOyBpIDwgeC5MZW5ndGg7IGkrKykKCQl7CgkJICAgIHZhciBzdWJzdHJpbmdzID0gbmV3IExpc3Q8c3RyaW5nPigpOwoJCSAgICBzdHJpbmcgc3RyID0geFtpXTsKCQkgICAgZm9yIChpbnQgYyA9IDA7IGMgPCBzdHIuTGVuZ3RoIC0gMTsgYysrKQoJCSAgICB7C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