EvgeniVT

Kamino Factory

Jun 23rd, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Kamino_Factory
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             int longDna = int.Parse(Console.ReadLine());
  11.             string commond = Console.ReadLine();
  12.  
  13.             int[] bestDnk = new int[longDna];
  14.             int bestSumDnk = 0;
  15.             int bestLenghtOne = 0;
  16.             int bestFirstIndexOne = 0;
  17.             int bestRow = 1;
  18.             int currentRow = 1;
  19.  
  20.             while (commond != "Clone them!")
  21.             {              
  22.                 int[] currentDnk = commond
  23.                     .Split("!", StringSplitOptions.RemoveEmptyEntries)
  24.                     .Select(int.Parse)
  25.                     .ToArray();
  26.  
  27.                 int currentSumDnk = currentDnk.Sum();
  28.  
  29.                 int bestCurrentLengthOne = 0;
  30.                 int currentFirstIndexOne = 0;
  31.  
  32.                 for (int i = 0; i < currentDnk.Length; i++)
  33.                 {
  34.                     int currentLenghOne = 0;
  35.  
  36.                     for (int j = i ; j < currentDnk.Length; j++)
  37.                     {
  38.                         if (currentDnk[i] == 1)
  39.                         {
  40.                             currentLenghOne++;
  41.                             i++;
  42.                         }
  43.                         else
  44.                         {
  45.                             break;
  46.                         }
  47.                     }
  48.                     if (currentLenghOne > bestCurrentLengthOne)
  49.                     {
  50.                         bestCurrentLengthOne = currentLenghOne;
  51.                         currentFirstIndexOne = i- currentLenghOne;
  52.                     }
  53.                 }
  54.  
  55.                 if (bestCurrentLengthOne > bestLenghtOne)
  56.                 {
  57.                     bestLenghtOne = bestCurrentLengthOne;
  58.                     bestRow = currentRow;
  59.                     bestSumDnk = currentSumDnk;
  60.                     bestDnk = currentDnk;
  61.                     bestFirstIndexOne = currentFirstIndexOne;
  62.                 }
  63.                 else if (bestCurrentLengthOne == bestLenghtOne)
  64.                 {
  65.                     if (currentFirstIndexOne < bestFirstIndexOne)
  66.                     {
  67.                         bestRow = currentRow;
  68.                         bestSumDnk = currentSumDnk;
  69.                         bestDnk = currentDnk;
  70.                         bestFirstIndexOne = currentFirstIndexOne;
  71.                     }
  72.                     else if (currentFirstIndexOne == bestFirstIndexOne)
  73.                     {
  74.                         if (currentSumDnk > bestSumDnk)
  75.                         {
  76.                             bestRow = currentRow;
  77.                             bestSumDnk = currentSumDnk;
  78.                             bestDnk = currentDnk;
  79.                         }
  80.  
  81.                     }                  
  82.                 }
  83.                 currentRow++;
  84.                 commond = Console.ReadLine();
  85.             }
  86.             Console.WriteLine($"Best DNA sample {bestRow} with sum: {bestSumDnk}.");
  87.             Console.WriteLine(string.Join(" ", bestDnk));
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment