Advertisement
Guest User

Untitled

a guest
Jan 31st, 2022
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.36 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _09._Kamino_Factory
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             int bestIndex = 1;
  12.             int bestIndexArray = 0;
  13.             int bestSum = 0;
  14.             int j = 1;
  15.             int maxInARow = int.MinValue;
  16.             int[] dnaSequemce = new int[n];
  17.             string value = string.Empty;
  18.             bool onlyZeroAndOne = true;
  19.             while ((value = Console.ReadLine())!="Clone them!")
  20.             {
  21.                 int[] arr = new int[n];
  22.                 arr = value.Split('!', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  23.                 for (int i = 0; i < arr.Length; i++)
  24.                 {
  25.                     if(arr[i]!=1 && arr[i] != 0)
  26.                     {
  27.                         onlyZeroAndOne = false;
  28.                     }
  29.                 }
  30.                 if (arr.Length== n && onlyZeroAndOne)
  31.                 {
  32.                     int inARow = 0;
  33.                     maxInARow = 0;
  34.                     int index = 0;
  35.                     int sum = 0;
  36.                     for (int i = 0; i < n; i++)
  37.                     {
  38.                         if (arr[i] == 1)
  39.                         {
  40.                             inARow++;
  41.                             if (inARow >= maxInARow)
  42.                             {
  43.                                 maxInARow = inARow;
  44.                                 if (inARow == 1)
  45.                                 {
  46.                                     index = i;
  47.                                 }
  48.                             }
  49.                             sum += arr[i];
  50.                         }
  51.                         else
  52.                         {
  53.                             inARow = 0;
  54.                         }
  55.                         if (j == 1)
  56.                         {
  57.                             dnaSequemce = arr;
  58.                             if (inARow >= maxInARow)
  59.                             {
  60.                                 maxInARow = inARow;
  61.                                 if (inARow == 1)
  62.                                 {
  63.                                     bestIndexArray = i;
  64.                                 }
  65.                             }
  66.                         }
  67.                     }
  68.                     if (index < bestIndexArray)
  69.                     {
  70.                         dnaSequemce = arr;
  71.                         bestSum = sum;
  72.                         bestIndex = j;
  73.                         bestIndexArray = index;
  74.                     }
  75.                     else if (index == bestIndexArray)
  76.                     {
  77.                         if (bestSum < sum)
  78.                         {
  79.                             dnaSequemce = arr;
  80.                             bestSum = sum;
  81.                             bestIndex = j;
  82.                         }
  83.                     }
  84.                     j++;
  85.                 }
  86.                 else
  87.                 {
  88.                     if (arr.Length==0 )
  89.                     {
  90.                         break;
  91.                     }
  92.                     continue;
  93.                 }
  94.             }
  95.             Console.WriteLine($"Best DNA sample {bestIndex} with sum: {bestSum}.");
  96.             Console.WriteLine(string.Join(" ", dnaSequemce));
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement