fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. HashSet<string> allWords = new HashSet<string> {
  10. "flame", "flaming", "flamingo", "funfair", "unfair"
  11. };
  12.  
  13. var query = allWords
  14. .Select(word => word.Substring(0, word.Length - 1))
  15. .Concat(allWords.Select(word => word.Substring(1, word.Length - 1)))
  16. .Where(candidate => allWords.Contains(candidate));
  17.  
  18. foreach (string word in query) {
  19. Console.WriteLine(word);
  20. }
  21. }
  22. }
Success #stdin #stdout 0.04s 37088KB
stdin
Standard input is empty
stdout
flaming
unfair