fork(2) download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8.  
  9.  
  10. public static void Main()
  11. {
  12. string[] x = new[] { "10111", "10122", "10250", "10113" };
  13. var allSubstrings = new Dictionary<int, List<string>>();
  14. for (int i = 0; i < x.Length; i++)
  15. {
  16. var substrings = new List<string>();
  17. string str = x[i];
  18. for (int c = 0; c < str.Length - 1; c++)
  19. {
  20. for (int cc = 1; c + cc <= str.Length; cc++)
  21. {
  22. string substr = str.Substring(c, cc);
  23. if (allSubstrings.Count < 1 || allSubstrings[allSubstrings.Count - 1].Contains(substr))
  24. substrings.Add(substr);
  25. }
  26. }
  27. allSubstrings.Add(i, substrings);
  28. }
  29. if (allSubstrings[allSubstrings.Count - 1].Count > 0)
  30. {
  31. string mostCommon = allSubstrings[allSubstrings.Count - 1]
  32. .GroupBy(str => str)
  33. .OrderByDescending(g => g.Key.Length)
  34. .ThenByDescending(g => g.Count())
  35. .First().Key;
  36. for (int i = 0; i < x.Length; i++)
  37. x[i] = x[i].Replace(mostCommon, "");
  38. }
  39. foreach(string str in x)
  40. Console.WriteLine(str);
  41. }
  42. }
Success #stdin #stdout 0.05s 35136KB
stdin
Standard input is empty
stdout
111
122
250
113