Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _9.KaminoFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int longDna = int.Parse(Console.ReadLine());
- string commond = Console.ReadLine();
- int[] bestDnk = new int[longDna];
- int bestSumDnk = 0;
- int bestLenghtOne = 1;
- int bestFirstIndexOne = 0;
- int bestRow = 0;
- int currentRow = 0;
- while (commond != "Clone them!")
- {
- currentRow++;
- int[] currentDnk = commond
- .Split("!", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int currentSumDnk = currentDnk.Sum();
- int bestCurrentLengthOne = 1;
- int currentFirstIndexOne = 0;
- for (int i = 0; i < currentDnk.Length; i++)
- {
- int currentLenghOne = 1;
- for (int j = i + 1; j < currentDnk.Length; j++)
- {
- if (currentDnk[i] == currentDnk[j] && currentDnk[j] == 1)
- {
- currentLenghOne++;
- }
- else
- {
- break;
- }
- }
- if (currentLenghOne > bestCurrentLengthOne)
- {
- bestCurrentLengthOne = currentLenghOne;
- currentFirstIndexOne = i;
- }
- }
- if (bestCurrentLengthOne > bestLenghtOne)
- {
- bestRow = currentRow;
- bestSumDnk = currentSumDnk;
- bestDnk = currentDnk;
- }
- else if (bestCurrentLengthOne == bestLenghtOne)
- {
- if (currentFirstIndexOne < bestFirstIndexOne)
- {
- bestRow = currentRow;
- bestSumDnk = currentSumDnk;
- bestDnk = currentDnk;
- }
- else if (currentFirstIndexOne > bestFirstIndexOne)
- {
- break;
- }
- else if (currentFirstIndexOne == bestFirstIndexOne)
- {
- if (currentSumDnk >= bestSumDnk)
- {
- bestRow = currentRow;
- bestSumDnk = currentSumDnk;
- bestDnk = currentDnk;
- }
- else
- {
- break;
- }
- }
- }
- else
- {
- break;
- }
- commond = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {bestRow} with sum: {bestSumDnk}.");
- Console.WriteLine(string.Join(" ", bestDnk));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement