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 input = Console.ReadLine();
- int DNACount = 0;
- int bestLength = 0;
- int bestStartIndex = -1;
- int bestSum = 0;
- int bestDNACount = -1;
- int[] bestDNA = new int[DNALength];
- while (input != "Clone them!")
- {
- int[] currentDNA = input
- .Split('!', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- DNACount += 1;
- int currentLength = 0;
- int currentSum = 0;
- int currentStartIndex = -1;
- for (int i = 0; i < currentDNA.Length; i++)
- {
- if (currentDNA[i] == 1)
- {
- currentSum += 1;
- }
- }
- for (int i = 0; i < currentDNA.Length; i++)
- {
- if (currentDNA[i] == 1)
- {
- currentLength += 1;
- if (currentLength == 1)
- {
- currentStartIndex = i;
- }
- }
- else
- {
- currentLength = 0;
- }
- if (currentLength > bestLength)
- {
- bestLength = currentLength;
- bestStartIndex = currentStartIndex;
- bestSum = currentSum;
- bestDNA = currentDNA;
- bestDNACount = DNACount;
- }
- else if (currentLength == bestLength && currentStartIndex < bestStartIndex)
- {
- bestStartIndex = currentStartIndex;
- bestSum = currentSum;
- bestDNA = currentDNA;
- bestDNACount = DNACount;
- }
- else if (currentLength == bestLength &&
- currentStartIndex == bestStartIndex && currentSum > bestSum)
- {
- bestDNA = currentDNA;
- bestDNACount = DNACount;
- bestSum = currentSum;
- }
- }
- input = Console.ReadLine();
- }
- if (bestLength ==0)
- {
- bestDNACount =1;
- }
- Console.WriteLine($"Best DNA sample {bestDNACount} with sum: {bestSum}.");
- Console.WriteLine($"{string.Join(' ', bestDNA)}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment