Advertisement
Guest User

Untitled

a guest
Dec 30th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03.Spyfer
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> listOfNumbers = Console.ReadLine()
  14. .Split(new char[] {' '} , StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToList();
  17.  
  18. int leftNeighboringElement = 0;
  19. int rightNeighboringElement = 0;
  20.  
  21. if (listOfNumbers.Count == 0)
  22. {
  23. Console.WriteLine("Empty");
  24. return;
  25. }
  26.  
  27. for (int index = 0; index < listOfNumbers.Count; index++)
  28. {
  29. leftNeighboringElement = index - 1 == -1 ? 0 : listOfNumbers[index - 1];
  30. rightNeighboringElement = index + 1 >= listOfNumbers.Count ? 0 : listOfNumbers[index + 1];
  31.  
  32. if (leftNeighboringElement + rightNeighboringElement == listOfNumbers[index])
  33. {
  34. // Console.WriteLine("Condition1");
  35. if (!(index == 0))
  36. {
  37. listOfNumbers.RemoveAt(index - 1);
  38. }
  39. if (!(index >= listOfNumbers.Count))
  40. {
  41. listOfNumbers.RemoveAt(index);
  42. }
  43. index = 0;
  44. }
  45. //else
  46. //{
  47. // Console.WriteLine("Nothing Happens");
  48. //}
  49. }
  50.  
  51. Console.WriteLine(string.Join(" ", listOfNumbers));
  52.  
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement