Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace P09.KaminoFactory
- {
- class KaminoFactory
- {
- static void Main(string[] args)
- {
- int lengthOfDNA = int.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- int counter = 0;
- int maxCountOfOnes = 0;
- int bestSequenceIndex = 0;
- int bestSequenceSum = 0;
- int[] bestDNA = new int[lengthOfDNA];
- while (command != "Clone them!")
- {
- int countOfOnes = 0;
- int maxCountOfOnesOfcurrentSequenceOfDNA = 0;
- int bestIndexOfcurrentSequenceOfDNA = 0;
- int bestSumOfcurrentSequenceOfDNA = 0;
- int[] currentSequenceOfDNA = new int[lengthOfDNA];
- string digits = string.Empty;
- for (int currentIndex = 0; currentIndex < command.Length; currentIndex++)
- {
- if (command[currentIndex] != '0' && command[currentIndex] != '1')
- {
- continue;
- }
- digits += command[currentIndex];
- }
- for (int currentIndex = 0; currentIndex < currentSequenceOfDNA.Length; currentIndex++)
- {
- currentSequenceOfDNA[currentIndex] = int.Parse(digits[currentIndex].ToString());
- }
- for (int currentIndex = 0; currentIndex < lengthOfDNA; currentIndex++)
- {
- if (currentSequenceOfDNA[currentIndex] == 1)
- {
- countOfOnes++;
- if (countOfOnes > maxCountOfOnesOfcurrentSequenceOfDNA)
- {
- maxCountOfOnesOfcurrentSequenceOfDNA = countOfOnes;
- if (currentIndex >= bestIndexOfcurrentSequenceOfDNA)
- {
- bestIndexOfcurrentSequenceOfDNA = currentIndex;
- }
- }
- bestSumOfcurrentSequenceOfDNA++;
- }
- else
- {
- countOfOnes = 0;
- }
- }
- if (maxCountOfOnesOfcurrentSequenceOfDNA > maxCountOfOnes)
- {
- maxCountOfOnes = maxCountOfOnesOfcurrentSequenceOfDNA;
- bestSequenceIndex = bestIndexOfcurrentSequenceOfDNA;
- bestSequenceSum = bestSumOfcurrentSequenceOfDNA;
- bestDNA = currentSequenceOfDNA;
- }
- else if (maxCountOfOnesOfcurrentSequenceOfDNA == maxCountOfOnes)
- {
- if (bestIndexOfcurrentSequenceOfDNA < bestSequenceIndex)
- {
- maxCountOfOnes = maxCountOfOnesOfcurrentSequenceOfDNA;
- bestSequenceIndex = bestIndexOfcurrentSequenceOfDNA;
- bestSequenceSum = bestSumOfcurrentSequenceOfDNA;
- bestDNA = currentSequenceOfDNA;
- bestSequenceIndex = bestIndexOfcurrentSequenceOfDNA;
- }
- else if (bestIndexOfcurrentSequenceOfDNA == bestSequenceIndex)
- {
- if (bestSumOfcurrentSequenceOfDNA > bestSequenceSum)
- {
- maxCountOfOnes = maxCountOfOnesOfcurrentSequenceOfDNA;
- bestSequenceIndex = bestIndexOfcurrentSequenceOfDNA;
- bestSequenceSum = bestSumOfcurrentSequenceOfDNA;
- bestDNA = currentSequenceOfDNA;
- }
- }
- }
- counter++;
- command = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {bestSequenceIndex} with sum: {bestSequenceSum}.");
- Console.Write(string.Join(' ', bestDNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement