Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace KaminoFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int DNALength = int.Parse(Console.ReadLine());
- string DNASequence = Console.ReadLine();
- int currentLength = 1;
- int bestLength = 0;
- int bestStartPosition = -1;
- int bestSequenceIndex = 0;
- int k = 0;
- int currentStartPosition = 0;
- int currentSequenceIndex = 0;
- int currentSum = 0;
- int bestSum = 0;
- int[] bestDNA = new int[DNASequence.Length];
- while (DNASequence != "Clone them!")
- {
- int[] currentDNA = DNASequence
- .Split('!', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- currentSequenceIndex += 1;
- currentSum = currentDNA.Sum();
- if (currentSum > bestSum)
- {
- bestSum = currentSum;
- }
- for (int i = 0; i < currentDNA.Length - 1; i++)
- {
- if (currentDNA[i] == currentDNA[i + 1] && currentDNA[i] != 0)
- {
- if (k == 0)
- {
- currentStartPosition = i;
- }
- currentLength += 1;
- k += 1;
- }
- else
- {
- currentLength = 1;
- k = 0;
- }
- if (currentLength > bestLength)
- {
- bestLength = currentLength;
- bestStartPosition = currentStartPosition;
- bestSequenceIndex = currentSequenceIndex;
- bestSum = currentSum;
- bestDNA = currentDNA;
- }
- else if (currentLength == bestLength)
- {
- if (currentStartPosition < bestStartPosition)
- {
- bestLength = currentLength;
- bestSum = currentSum;
- bestStartPosition = currentStartPosition;
- bestSequenceIndex = currentSequenceIndex;
- bestDNA = currentDNA;
- }
- else if (currentStartPosition == bestStartPosition)
- {
- if (currentSum > bestSum)
- {
- bestSum = currentSum;
- bestStartPosition = currentStartPosition;
- bestSequenceIndex = currentSequenceIndex;
- bestLength = currentLength;
- bestDNA = currentDNA;
- }
- }
- }
- }
- DNASequence = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {bestSequenceIndex} with sum: {bestSum}.");
- Console.WriteLine(string.Join(' ', bestDNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement