fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string input = "all our vidphone lines here are trapped. they recirculate the call to other offices within the building";
  9.  
  10. var queryList = new List<string> { "other", "they", "all", "building" };
  11.  
  12. string[] stack = input.Split(' ');
  13.  
  14. foreach (var word in queryList)
  15. {
  16. for (int i = 0; i < stack.Length; i++)
  17. {
  18. if (word != stack[i]) continue;
  19.  
  20. Console.WriteLine($"Found: {word}");
  21. Console.WriteLine(i > 0 ? $"Left: {stack[i-1]}" : "Left: (NONE)");
  22. Console.WriteLine(i < stack.Length - 1 ? $"Right: {stack[i+1]}" : "Right: (NONE)");
  23. Console.WriteLine();
  24. }
  25. }
  26.  
  27. Console.ReadLine();
  28. }
  29. }
Success #stdin #stdout 0s 29672KB
stdin
Standard input is empty
stdout
Found: other
Left: to
Right: offices

Found: they
Left: trapped.
Right: recirculate

Found: all
Left: (NONE)
Right: our

Found: building
Left: the
Right: (NONE)