Advertisement
mellowdeep

Sequence of K Numbers

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