Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _2.SequenceOfK_Numbers
- {
- using System;
- using System.Collections.Generic;
- public class SequenceOfK_Numbers
- {
- public static void Main(string[] args)
- {
- checked
- {
- string inputLine = Console.ReadLine();
- int numK = int.Parse(Console.ReadLine());
- if (numK > 1)
- {
- int[] seqNums = SplitInputStringAndCreateArrayOfNumbers(inputLine);
- int countOfEquals = 1;
- for (int i = 1; i < seqNums.Length; i++)
- {
- int previousNum = seqNums[i - 1];
- if (i < seqNums.Length - 1)
- {
- if (seqNums[i] == previousNum)
- {
- countOfEquals++;
- }
- else
- {
- PrintNextRightNumber(numK, countOfEquals, previousNum);
- countOfEquals = 1;
- }
- }
- else
- {
- if (seqNums[i] == previousNum)
- {
- countOfEquals++;
- PrintNextRightNumber(numK, countOfEquals, previousNum);
- }
- else
- {
- Console.WriteLine(seqNums[i]);
- }
- }
- }
- }
- }
- }
- private static void PrintNextRightNumber(int numK, int countOfEquals, int previousNum)
- {
- checked
- {
- int maxWrite = countOfEquals % numK;
- for (int j = 0; j < maxWrite; j++)
- {
- Console.Write("{0} ", previousNum);
- }
- }
- }
- private static int[] SplitInputStringAndCreateArrayOfNumbers(string inputStr)
- {
- checked
- {
- char[] separators = new char[] { ' ', ',', ';' };
- string[] numStr = inputStr.Split(separators, StringSplitOptions.RemoveEmptyEntries);
- int[] nums = new int[numStr.Length];
- for (int i = 0; i < numStr.Length; i++)
- {
- nums[i] = int.Parse(numStr[i]);
- }
- return nums;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement