Danny_Berova

03.Spyfer

Aug 5th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1.  
  2. namespace _03.Spyfer
  3. {
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.     public class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             List<int> coordinates = Console.ReadLine()
  13.                 .Split()
  14.                 .Select(int.Parse)
  15.                 .ToList();
  16.  
  17.             for (int i = 0; i < coordinates.Count; i++)
  18.             {
  19.                 int currentNumber = coordinates[i];
  20.  
  21.                 if (i != 0 && i != coordinates.Count - 1)
  22.                 {
  23.                     if (currentNumber == coordinates[i - 1] + coordinates[i + 1])
  24.                     {
  25.                         coordinates.RemoveAt(i + 1);
  26.                         coordinates.RemoveAt(i - 1);
  27.  
  28.                         i = 0;
  29.                     }
  30.                 }
  31.                 else if (i == 0 && currentNumber == coordinates[i + 1])
  32.                 {
  33.                     coordinates.RemoveAt(i + 1);
  34.                     i = 0;
  35.                 }
  36.                 else if (i == coordinates.Count - 1
  37.                     && currentNumber == coordinates[i - 1])
  38.                 {
  39.                     coordinates.RemoveAt(i - 1);
  40.                     i = 0;
  41.                 }
  42.  
  43.             }
  44.  
  45.             Console.WriteLine(string.Join(" ", coordinates));
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment