Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 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 ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int length = int.Parse(Console.ReadLine());
  14.             int[] bestArr = new int[length];
  15.             int sequenceCounter = 0;
  16.             string arr = Console.ReadLine();
  17.             int maxSubSeqLen = 0;
  18.             int maxSubSeqSum = 0;
  19.             int bestStartPos = 0;
  20.             int bestArrSum = 0;
  21.             int counter = 0;
  22.             while (arr != "Clone them!")
  23.             {
  24.                 int[] currentArr = arr.Split('!').Select(int.Parse).ToArray();
  25.                 int currentArrSum = 0;
  26.                 sequenceCounter++;
  27.                 int currentStartPosition = 0;
  28.                 int currentLength = 0;
  29.                 for (int i = 0; i < length; i++)
  30.                 {
  31.                     currentArrSum += currentArr[i];
  32.                     if (currentArr[i] == 1)
  33.                     {
  34.                         currentLength++;
  35.                         currentStartPosition = i;
  36.                     }
  37.                    
  38.                     if (currentLength > maxSubSeqLen || (currentLength == maxSubSeqLen && currentStartPosition < bestStartPos) || (currentLength == maxSubSeqLen && currentStartPosition == bestStartPos && currentArrSum > maxSubSeqSum))
  39.                     {
  40.                         maxSubSeqLen = currentLength;
  41.                         maxSubSeqSum = currentArrSum;
  42.                         bestArr = currentArr;
  43.                         bestArrSum = currentArrSum;
  44.                         counter = sequenceCounter;
  45.                         bestStartPos = currentStartPosition;
  46.                     }
  47.  
  48.                 }
  49.                 currentLength = 0;
  50.                 currentStartPosition = 0;
  51.                 currentArrSum = 0;
  52.                 arr = Console.ReadLine();
  53.             }
  54.             Console.WriteLine("Best DNA sample {0} with sum: {1}.", counter, maxSubSeqSum);
  55.             Console.WriteLine(string.Join(" ", bestArr));
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement