Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _9.KaminoFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int dnaLength = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- int[] bestDnaArray = new int[dnaLength];
- int leftmostIndex = 0;
- int greaterSum = 0;
- int greaterSequence = 0;
- int inputCounter = 0;
- int bestCounter = 0;
- while (true)
- {
- if(input == "Clone them!")
- {
- break;
- }
- inputCounter++;
- int[] dnaArray = new int[dnaLength];
- int counter = 0;
- for(int i = 0; i < input.Length; i++)
- {
- char symbol = input[i];
- if(symbol != '!' || symbol != ' ')
- {
- if(symbol == '0' || symbol == '1')
- {
- dnaArray[counter] = int.Parse(symbol.ToString());
- counter++;
- }
- }
- }
- int bestSum = 0;
- int sequence = 0;
- int bestIndex = 0;
- for (int i = 0; i < dnaArray.Length; i++)
- {
- int index = 0;
- if (dnaArray[i] == 1)
- {
- int sum = 0;
- index = i;
- for (int j = i; j < dnaArray.Length; j++)
- {
- if (dnaArray[j] == 0)
- {
- i = j;
- break;
- }
- sum++;
- i = j;
- }
- if(sum > bestSum)
- {
- bestSum = sum;
- bestIndex = index;
- sequence = bestSum;
- }
- }
- }
- int arraySum = 0;
- for (int i = 0; i < dnaArray.Length; i++)
- {
- if (dnaArray[i] == 1)
- {
- arraySum++;
- }
- }
- if (sequence > greaterSequence)
- {
- bestDnaArray = dnaArray;
- leftmostIndex = bestIndex;
- bestCounter = inputCounter;
- greaterSum = arraySum;
- greaterSequence = sequence;
- }
- else if(sequence == greaterSequence)
- {
- if(bestIndex < leftmostIndex)
- {
- bestDnaArray = dnaArray;
- leftmostIndex = bestIndex;
- greaterSum = arraySum;
- bestCounter = inputCounter;
- }
- else if(bestIndex == leftmostIndex)
- {
- if(greaterSum < arraySum)
- {
- bestDnaArray = dnaArray;
- leftmostIndex = bestIndex;
- greaterSum = arraySum;
- bestCounter = inputCounter;
- }
- }
- }
- input = Console.ReadLine();
- }
- if (bestCounter == 0)
- {
- bestCounter = 1;
- }
- Console.WriteLine($"Best DNA sample {bestCounter} with sum: {greaterSum}.");
- Console.WriteLine($"{string.Join(" ", bestDnaArray)}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement