fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<string> validatedStrings = new List<string>();
  10. List<string> subjectStrings = new List<string>()
  11. {
  12. "con", "cot", "eon", "net", "not", "one", "ten", "toe", "ton",
  13. "cent", "cone", "conn", "cote", "neon", "none", "note", "once", "tone",
  14. "cento", "conte", "nonce", "nonet", "oncet", "tenon", "tonne",
  15. "nocent","concent", "connect"
  16. }; //got a more longer wordlist
  17.  
  18. string startswithString = "co";
  19. string endswithString = "et";
  20.  
  21.  
  22. var sw =getCombinations(startswithString);
  23. var ew = getCombinations(endswithString);
  24.  
  25.  
  26. validatedStrings = subjectStrings.Where(z=>
  27. sw.Any(x=>z.StartsWith(x) &&
  28. !ew.Any(y=>z.EndsWith(y))))
  29. .ToList();
  30.  
  31.  
  32. foreach(var a in validatedStrings)
  33. {
  34. Console.WriteLine(a);
  35. }
  36. Console.WriteLine("\nDone");
  37. }
  38.  
  39.  
  40. static List<string> getCombinations(string s)
  41. {
  42. //Code that calculates combinations
  43. return Permutations.Permutate(s);
  44. }
  45. }
  46.  
  47. public class Permutations
  48. {
  49. private static List<List<string>> allCombinations;
  50.  
  51. private static void CalculateCombinations(string word, List<string> temp)
  52. {
  53. if (temp.Count == word.Length)
  54. {
  55. List<string> clone = temp.ToList();
  56. if (clone.Distinct().Count() == clone.Count)
  57. {
  58. allCombinations.Add(clone);
  59. }
  60. return;
  61. }
  62.  
  63. for (int i = 0; i < word.Length; i++)
  64. {
  65. temp.Add(word[i].ToString());
  66. CalculateCombinations(word, temp);
  67. temp.RemoveAt(temp.Count - 1);
  68. }
  69. }
  70.  
  71. public static List<string> Permutate(string str)
  72. {
  73. allCombinations = new List<List<string>>();
  74. CalculateCombinations(str, new List<string>());
  75. List<string> combinations = new List<string>();
  76. foreach(var a in allCombinations)
  77. {
  78. string c = "";
  79. foreach(var b in a)
  80. {
  81. c+=b;
  82. }
  83. combinations.Add(c);
  84. }
  85. return combinations;
  86. }
  87. }
Success #stdin #stdout 0.07s 34184KB
stdin
Standard input is empty
stdout
con
cot
cone
conn
concent
connect

Done