nikiman8888

Spyfer Exam

May 19th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Linq;
  6.  
  7. namespace lab3.Spyfer
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15.             if (input.Count < 2)
  16.             {
  17.                 Console.WriteLine(string.Join(" ", input));
  18.                 return;
  19.             }
  20.             else
  21.             {
  22.                 int counter = 0;
  23.                 while (counter != input.Count)
  24.                 {
  25.                     if (input.Count == 1)
  26.                     {
  27.                         Console.WriteLine(string.Join(" ", input));
  28.                         return;
  29.                     }
  30.  
  31.                     for (int i = 0; i < input.Count; i++)
  32.                     {
  33.                         if (i == 0)
  34.                         {
  35.                             if (input[i] == input[i + 1])
  36.                             {
  37.                                 input.RemoveAt(i + 1);
  38.                                 counter = 0;
  39.                                 break;
  40.                             }
  41.                         }
  42.                         else if (i == input.Count - 1)
  43.                         {
  44.                             if (input[i] == input[i - 1])
  45.                             {
  46.                                 input.RemoveAt(i - 1);
  47.                                 counter = 0;
  48.                                 break;
  49.                             }
  50.                         }
  51.                         else if (input[i - 1] + input[i + 1] == input[i])
  52.                         {
  53.                             input = RemoveNeghbours(input, i - 1, i + 1).ToList();
  54.                             counter = 0;
  55.                             break;
  56.  
  57.                         }
  58.                         counter++;
  59.                     }
  60.  
  61.                 }
  62.                 Console.WriteLine(string.Join(" ", input));
  63.             }
  64.  
  65.  
  66.         }
  67.  
  68.         private static List<int> RemoveNeghbours(List<int> input, int v1, int v2)
  69.         {
  70.             List<int> temp = new List<int>();
  71.             for (int i = 0; i < input.Count; i++)
  72.             {
  73.                 if (i == v1 || i == v2)
  74.                 {
  75.                     continue;
  76.                 }
  77.                 else
  78.                 {
  79.                     temp.Add(input[i]);
  80.                 }
  81.             }
  82.             return temp;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment