fbinnzhivko

02.01 Sequence of K Numbers

Apr 15th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class SequenceOfKNumbers
  5.     {
  6.         public static List<int> printCollection = new List<int>();
  7.         private static void GetList(List<int> inputCollection, int elementK, int startPos)
  8.         {
  9.  
  10.             int checkForSequence = 1;
  11.             for (int i = 0; i < elementK - 1; i++)
  12.             {
  13.                 if (startPos + i >= inputCollection.Count)
  14.                 {
  15.                     printCollection.AddRange(inputCollection);
  16.                     return;
  17.                 }
  18.                 if ((i + startPos + 1) < inputCollection.Count)
  19.                 {
  20.                     if (inputCollection[i + startPos] == inputCollection[i + startPos + 1])
  21.                     {
  22.                         checkForSequence++;
  23.                     }
  24.                 }
  25.             }
  26.             if (checkForSequence == elementK)
  27.             {
  28.                 inputCollection.RemoveRange(0 + startPos, elementK);
  29.                 GetList(inputCollection, elementK, startPos);
  30.             }
  31.             else
  32.             {
  33.                 GetList(inputCollection, elementK, startPos + 1);
  34.             }
  35.  
  36.         }
  37.  
  38.         static void Main()
  39.         {
  40.             List<int> inputCollection = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
  41.             int elementK = int.Parse(Console.ReadLine());
  42.             if (elementK != 1)
  43.             {
  44.                 GetList(inputCollection, elementK, 0);
  45.             }
  46.             foreach (int item in printCollection)
  47.             {
  48.                 Console.Write("{0} ", item);
  49.             }
  50.         }
  51.     }
Add Comment
Please, Sign In to add comment