Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Linq;
- namespace lab3.Spyfer
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- if (input.Count < 2)
- {
- Console.WriteLine(string.Join(" ", input));
- return;
- }
- else
- {
- int counter = 0;
- while (counter != input.Count)
- {
- if (input.Count == 1)
- {
- Console.WriteLine(string.Join(" ", input));
- return;
- }
- for (int i = 0; i < input.Count; i++)
- {
- if (i == 0)
- {
- if (input[i] == input[i + 1])
- {
- input.RemoveAt(i + 1);
- counter = 0;
- break;
- }
- }
- else if (i == input.Count - 1)
- {
- if (input[i] == input[i - 1])
- {
- input.RemoveAt(i - 1);
- counter = 0;
- break;
- }
- }
- else if (input[i - 1] + input[i + 1] == input[i])
- {
- input = RemoveNeghbours(input, i - 1, i + 1).ToList();
- counter = 0;
- break;
- }
- counter++;
- }
- }
- Console.WriteLine(string.Join(" ", input));
- }
- }
- private static List<int> RemoveNeghbours(List<int> input, int v1, int v2)
- {
- List<int> temp = new List<int>();
- for (int i = 0; i < input.Count; i++)
- {
- if (i == v1 || i == v2)
- {
- continue;
- }
- else
- {
- temp.Add(input[i]);
- }
- }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment