Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace P09_KaminoFactory
- {
- using System;
- using System.Linq;
- class P09_KaminoFactory
- {
- static void Main(string[] args)
- {
- int sequenceLength = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- int[] DNA = new int[sequenceLength];
- int DNASum = 0;
- int DNACount = 0;
- int DNASample = 0;
- int sample = 0;
- while (input != "Clone them!")
- {
- //----------------------------- CURRENT DNA INFO -----------------------------
- sample++;
- int[] currDNA = input.Split("!", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int sum = 0;
- int currCount = 0;
- int count = 0;
- for (int i = currDNA.Length - 1; i >= 0; i--)
- {
- if (currDNA[i] != 1)
- {
- count = 0;
- continue;
- }
- sum++;
- count++;
- if (count >= currCount)
- {
- currCount = count;
- }
- }
- //----------------------------------------------------------------------------
- //------------------ Check CURRENT DNA with BEST DNA -------------------------
- if (currCount > DNACount)
- {
- DNACount = currCount;
- DNASum = sum;
- DNA = currDNA;
- DNASample = sample;
- }
- else if (currCount == DNACount)
- {
- int count1 = 0;
- int count2 = 0;
- bool isDNAFirst = false;
- bool isCurrDNAFirst = false;
- //---------------- Find the leftmost best DNA ----------------------------
- for (int i = 0; i < sequenceLength; i++)
- {
- //--------- Best DNA ----------
- if (DNA[i] == 1)
- {
- count1++;
- if (count1 == DNACount)
- {
- isDNAFirst = true;
- }
- }
- else
- {
- count1 = 0;
- }
- //------- Current DNA ---------
- if (currDNA[i] == 1)
- {
- count2++;
- if (count2 == currCount)
- {
- isCurrDNAFirst = true;
- }
- }
- else
- {
- count2 = 0;
- }
- //-----------------------------
- if (isDNAFirst || isCurrDNAFirst)
- {
- break;
- }
- }
- //--------- IF BOTH ARE EQUAL CHECK THEIR SUMS ---------
- if (isDNAFirst && isCurrDNAFirst)
- {
- if (sum > DNASum)
- {
- // current DNA is better
- DNA = currDNA;
- DNASum = sum;
- DNACount = currCount;
- DNASample = sample;
- }
- }
- //--------- IF CURRENT DNA IS BETTER -------------------
- else if (isCurrDNAFirst)
- {
- DNA = currDNA;
- DNASum = sum;
- DNACount = currCount;
- DNASample = sample;
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {DNASample} with sum: {DNASum}.");
- Console.WriteLine(String.Join(" ", DNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement