Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- string[] bestDna = null;
- int bestLen = -1;
- int startIndex = -1;
- int bestDnaSum = 0;
- int bestSampleIndex = 0;
- int currentSampleIndex = 0;
- while (input != "Clone them!")
- {
- string[] currentDna = input.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- int currentLen = 0;
- int currentBestLen = 0;
- int currentEndIndex = 0;
- for (int i = 0; i < currentDna.Length; i++)
- {
- if (currentDna[i] == "1")
- {
- currentLen++;
- if (currentLen > currentBestLen)
- {
- currentEndIndex = i;
- currentBestLen = currentLen;
- }
- }
- else
- {
- currentLen = 0;
- }
- }
- int currentStartIndex = currentEndIndex - currentBestLen + 1;
- bool isCurrentDnaBetter = false;
- int currentDnaSum = currentDna.Select(int.Parse).Sum();
- if (currentBestLen > bestLen)
- {
- isCurrentDnaBetter = true;
- }
- else if (currentBestLen == bestLen)
- {
- if (currentStartIndex < startIndex)
- {
- isCurrentDnaBetter = true;
- }
- else if (currentStartIndex == startIndex)
- {
- if (currentDnaSum > bestDnaSum)
- {
- isCurrentDnaBetter = true;
- }
- }
- }
- currentSampleIndex++;
- if (isCurrentDnaBetter)
- {
- bestDna = currentDna;
- bestLen = currentBestLen;
- startIndex = currentStartIndex;
- bestDnaSum = currentDnaSum;
- bestSampleIndex = currentSampleIndex;
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {bestSampleIndex} with sum: {bestDnaSum}.");
- Console.WriteLine(string.Join(" ", bestDna));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement