Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _03.Spyfer
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- List<int> coordinates = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- for (int i = 0; i < coordinates.Count; i++)
- {
- int currentNumber = coordinates[i];
- if (i != 0 && i != coordinates.Count - 1)
- {
- if (currentNumber == coordinates[i - 1] + coordinates[i + 1])
- {
- coordinates.RemoveAt(i + 1);
- coordinates.RemoveAt(i - 1);
- i = 0;
- }
- }
- else if (i == 0 && currentNumber == coordinates[i + 1])
- {
- coordinates.RemoveAt(i + 1);
- i = 0;
- }
- else if (i == coordinates.Count - 1
- && currentNumber == coordinates[i - 1])
- {
- coordinates.RemoveAt(i - 1);
- i = 0;
- }
- }
- Console.WriteLine(string.Join(" ", coordinates));
- }
- }
- }
Add Comment
Please, Sign In to add comment