Advertisement
Guest User

Untitled

a guest
May 24th, 2018
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _02._Kamino_Factory
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int lengthOfSequences = int.Parse(Console.ReadLine());
  11.  
  12.             string line = Console.ReadLine();
  13.  
  14.             string[] bestSequence = null;
  15.             int bestSequenceLenght = 0;
  16.             int bestSequenceIndex = 0;
  17.             int bestSequenceSumOnes = 0;
  18.             int sample = 0;
  19.             int bestSample = 0;
  20.  
  21.             while (line != "Clone them!")
  22.             {
  23.  
  24.                 sample++;
  25.                 var currentSequence = line.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries);
  26.                 int currentSequenceLenght = 0;
  27.                 int currentSequenceStartIndex = 0;
  28.                 int currentSequenceSumOnes = 0;
  29.                 bool newSequenceStarted = true;
  30.  
  31.                 for (int j = 0; j < currentSequence.Length; j++)
  32.                 {
  33.                     if (currentSequence[j] == "1")
  34.                     {
  35.                         currentSequenceSumOnes++;
  36.                     }
  37.                 }
  38.  
  39.                 for (int i = 0; i < currentSequence.Length; i++)
  40.                 {
  41.                     if (currentSequence[i] != "1")
  42.                     {
  43.                         currentSequenceLenght = 0;
  44.                         newSequenceStarted = true;
  45.                     }
  46.                     else
  47.                     {
  48.                         currentSequenceLenght++;
  49.                         if (newSequenceStarted)
  50.                         {
  51.                             newSequenceStarted = false;
  52.                             currentSequenceStartIndex = i;
  53.                         }
  54.                     }
  55.  
  56.                     if (currentSequenceLenght > bestSequenceLenght || bestSequence == null
  57.                         || (currentSequenceLenght == bestSequenceLenght && currentSequenceStartIndex < bestSequenceIndex)
  58.                         || (currentSequenceLenght == bestSequenceLenght && currentSequenceStartIndex == bestSequenceIndex && currentSequenceSumOnes > bestSequenceSumOnes))
  59.                     {
  60.                         bestSequenceLenght = currentSequenceLenght;
  61.                         bestSequenceIndex = currentSequenceStartIndex;
  62.                         bestSequence = (string[])currentSequence;
  63.                         bestSequenceSumOnes = currentSequenceSumOnes;
  64.                         bestSample = sample;
  65.                     }
  66.                 }
  67.                 line = Console.ReadLine();
  68.             }
  69.             Console.WriteLine($"Best DNA sample {bestSample} with sum: {bestSequenceSumOnes}.");
  70.             Console.WriteLine($"{string.Join(" ", bestSequence)}");
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement