Advertisement
fbinnzhivko

02.00 Sequence of K Numbers

Apr 15th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. class KSequence
  3. {
  4.     static void Main()
  5.     {
  6.         string inputLine = Console.ReadLine();
  7.         int k = int.Parse(Console.ReadLine());
  8.  
  9.         inputLine = inputLine + " " + int.MaxValue;
  10.         string[] inputTokens = inputLine.Split(' ');
  11.         int equalCount = 1;
  12.         int prev = int.Parse(inputTokens[0]);
  13.         for (int i = 1; i < inputTokens.Length; i++)
  14.         {
  15.             int num = int.Parse(inputTokens[i]);
  16.             if (num == prev)
  17.             {
  18.                 equalCount++;
  19.             }
  20.             else
  21.             {
  22.                 // Print (count % k) times the number num
  23.                 for (int counter = 0; counter < equalCount % k; counter++)
  24.                 {
  25.                     Console.Write(prev + " ");
  26.                 }
  27.                 equalCount = 1;
  28.             }
  29.             prev = num;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement