Advertisement
Guest User

Untitled

a guest
May 24th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 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.                 // remove multiple !!..
  25.                 // RegexOptions options = RegexOptions.None;
  26.                 // Regex regex = new Regex("[!]{2,}", options);
  27.                 // line = regex.Replace(line, "!");
  28.                
  29.                 sample++;
  30.                 var currentSequence = line.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries);
  31.                 int currentSequenceLenght = 0;
  32.                 int currentSequenceStartIndex = 0;
  33.                 int currentSequenceSumOnes = 0;
  34.                 bool newSequenceStarted = true;
  35.                
  36.                 for (int j = 0; j < currentSequence.Length; j++)
  37.                 {
  38.                     if (currentSequence[j] == "1")
  39.                     {
  40.                         currentSequenceSumOnes++;
  41.                     }
  42.                 }
  43.  
  44.                 for (int i = 0; i < currentSequence.Length; i++)
  45.                 {
  46.                     if (currentSequence[i] != "1")
  47.                     {
  48.                         currentSequenceLenght = 0;
  49.                         newSequenceStarted = true;
  50.                     }
  51.                     else
  52.                     {
  53.                         currentSequenceLenght++;
  54.                         if (newSequenceStarted)
  55.                         {
  56.                             newSequenceStarted = false;
  57.                             currentSequenceStartIndex = i;
  58.                         }
  59.                     }
  60.  
  61.                     if ((currentSequenceLenght > bestSequenceLenght)
  62.                         || (currentSequenceLenght == bestSequenceLenght && currentSequenceStartIndex < bestSequenceIndex)
  63.                         || (currentSequenceLenght == bestSequenceLenght && currentSequenceStartIndex == bestSequenceIndex && currentSequenceSumOnes > bestSequenceSumOnes))
  64.                     {
  65.                         bestSequenceLenght = currentSequenceLenght;
  66.                         bestSequenceIndex = currentSequenceStartIndex;
  67.                         bestSequence = (string[])currentSequence.Clone();
  68.                         bestSequenceSumOnes = currentSequenceSumOnes;
  69.                         bestSample = sample;
  70.                     }
  71.                 }
  72.                 line = Console.ReadLine();
  73.             }
  74.             Console.WriteLine($"Best DNA sample {bestSample} with sum: {bestSequenceSumOnes}.");
  75.             Console.WriteLine($"{string.Join(" ", bestSequence)}");
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement