fork(4) 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. foreach(var z in subjectStrings)
  22. {
  23. bool valid = false;
  24. foreach(var a in getCombinations(startswithString))
  25. {
  26. foreach(var b in getCombinations(endswithString))
  27. {
  28. if(z.StartsWith(a) && !z.EndsWith(b))
  29. {
  30. valid = true;
  31. break;
  32. }
  33. }
  34. if(valid)
  35. {
  36. break;
  37. }
  38. }
  39. if(valid)
  40. {
  41. validatedStrings.Add(z);
  42. }
  43. }
  44.  
  45. foreach(var a in validatedStrings)
  46. {
  47. Console.WriteLine(a);
  48. }
  49. Console.WriteLine("\nDone");
  50. }
  51.  
  52.  
  53. static List<string> getCombinations(string s)
  54. {
  55. //Code that calculates combinations
  56. return Permutations.Permutate(s);
  57. }
  58. }
  59.  
  60. public class Permutations
  61. {
  62. private static List<List<string>> allCombinations;
  63.  
  64. private static void CalculateCombinations(string word, List<string> temp)
  65. {
  66. if (temp.Count == word.Length)
  67. {
  68. List<string> clone = temp.ToList();
  69. if (clone.Distinct().Count() == clone.Count)
  70. {
  71. allCombinations.Add(clone);
  72. }
  73. return;
  74. }
  75.  
  76. for (int i = 0; i < word.Length; i++)
  77. {
  78. temp.Add(word[i].ToString());
  79. CalculateCombinations(word, temp);
  80. temp.RemoveAt(temp.Count - 1);
  81. }
  82. }
  83.  
  84. public static List<string> Permutate(string str)
  85. {
  86. allCombinations = new List<List<string>>();
  87. CalculateCombinations(str, new List<string>());
  88. List<string> combinations = new List<string>();
  89. foreach(var a in allCombinations)
  90. {
  91. string c = "";
  92. foreach(var b in a)
  93. {
  94. c+=b;
  95. }
  96. combinations.Add(c);
  97. }
  98. return combinations;
  99. }
  100. }
Success #stdin #stdout 0.07s 34232KB
stdin
Standard input is empty
stdout
con
cot
cone
conn
cote
conte
concent
connect

Done