Advertisement
Guest User

Untitled

a guest
Oct 24th, 2018
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _09.KaminoFactory
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = string.Empty;
  14.             int length = int.Parse(Console.ReadLine());
  15.             int[] lss = new int[length];
  16.             int lssLength = int.MinValue, lssIndex = int.MinValue, lssSum = int.MinValue, lssStart = -1;
  17.             int index = 1;
  18.  
  19.             while ((input = Console.ReadLine()) != "Clone them!")
  20.             {
  21.                 int[] data = input
  22.                     .Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries)
  23.                     .Select(int.Parse)
  24.                     .ToArray();
  25.  
  26.                 int currentLength = int.MinValue, currentIndex = int.MinValue, currentSubLength = 0, currentSubIndex = 0;
  27.                 bool isOne = false;
  28.  
  29.                 for (int i = 0; i < length; i++)
  30.                 {
  31.                     if (data[i] == 1 && isOne)
  32.                     {
  33.                         currentSubLength++;
  34.                     }
  35.                     else if (data[i] == 1)
  36.                     {
  37.                         isOne = true;
  38.                         currentSubIndex = i;
  39.                         currentSubLength = 1;
  40.                     }
  41.                     else if (data[i] == 0 && isOne)
  42.                     {
  43.                         if (currentSubLength > currentLength)
  44.                         {
  45.                             currentLength = currentSubLength;
  46.                             currentIndex = currentSubIndex;
  47.                         }
  48.                         isOne = false;
  49.                         currentSubLength = 0;
  50.                         currentSubIndex = 0;
  51.                     }
  52.                 }
  53.  
  54.                 if (isOne)
  55.                 {
  56.                     if (currentSubLength > currentLength)
  57.                     {
  58.                         currentLength = currentSubLength;
  59.                         currentIndex = currentSubIndex;
  60.                     }
  61.                 }
  62.  
  63.                 if (currentLength > lssLength)
  64.                 {
  65.                     lssLength = currentLength;
  66.                     lssIndex = currentIndex;
  67.                     lssSum = data.Sum();
  68.                     lss = data;
  69.                     lssStart = index;
  70.                 }
  71.                 else if (currentLength == lssLength)
  72.                 {
  73.                     if (currentIndex < lssIndex)
  74.                     {
  75.                         lssLength = currentLength;
  76.                         lssIndex = currentIndex;
  77.                         lssSum = data.Sum();
  78.                         lss = data;
  79.                         lssStart = index;
  80.                     }
  81.                     else if (currentIndex == lssIndex)
  82.                     {
  83.                         if (data.Sum() > lssSum)
  84.                         {
  85.                             lssLength = currentLength;
  86.                             lssIndex = currentIndex;
  87.                             lssSum = data.Sum();
  88.                             lss = data;
  89.                             lssStart = index;
  90.                         }
  91.                     }
  92.                 }
  93.                 index++;
  94.             }
  95.  
  96.             Console.WriteLine($"Best DNA sample {lssStart} with sum: {lssSum}.");
  97.             Console.WriteLine(string.Join(" ", lss));
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement