Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace KaminoFactory
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- int bestLengthDNA = 0;
- int bestENDIndex = 0;
- int bestDNASum = 0;
- int currentDNACounter = 0;
- int bestDNACounter = 0;
- int[] bestDNA = new int [n];
- while (input != "Clone them!")
- {
- int currentLengthOfOne = 1;
- int bestCurrentLengthOfOne = 0;
- int currentENDIndex = 0;
- int currentSum = 0;
- int[] currentDNA = input.Split("!",StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- currentDNACounter++;
- for (int i = 0; i < currentDNA.Length - 1; i++)
- {
- if (currentDNA[i] == currentDNA[i + 1])
- {
- currentLengthOfOne++;
- }
- else if (currentDNA[i] != currentDNA[i + 1])
- {
- currentLengthOfOne = 1;
- }
- if (currentLengthOfOne > bestCurrentLengthOfOne)
- {
- bestCurrentLengthOfOne = currentLengthOfOne;
- currentENDIndex = i;
- }
- }
- currentSum = currentDNA.Sum();
- if (bestCurrentLengthOfOne > bestLengthDNA)
- {
- bestDNA = currentDNA.ToArray();
- bestLengthDNA = bestCurrentLengthOfOne;
- bestENDIndex = currentENDIndex;
- bestDNASum = currentSum;
- bestDNACounter = currentDNACounter;
- }
- else if (bestCurrentLengthOfOne == bestLengthDNA)
- {
- if (currentENDIndex < bestENDIndex)
- {
- bestDNA = currentDNA.ToArray();
- bestLengthDNA = bestCurrentLengthOfOne;
- bestENDIndex = currentENDIndex;
- bestDNASum = currentSum;
- bestDNACounter = currentDNACounter;
- }
- else if (currentENDIndex == bestENDIndex)
- {
- if (currentSum > bestDNASum)
- {
- bestDNA = currentDNA.ToArray();
- bestLengthDNA = bestCurrentLengthOfOne;
- bestENDIndex = currentENDIndex;
- bestDNASum = currentSum;
- bestDNACounter = currentDNACounter;
- }
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {bestDNACounter} with sum: {bestDNASum}.");
- Console.WriteLine(string.Join(" ",bestDNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement