Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _9_KaminoFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- int maxSequence = 0;
- int leftMostIndex = int.MaxValue;
- int sum = 0;
- int[] arrMax = new int[n];
- while (command != "Clone them!")
- {
- int[] arr = command.Split("!", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int counter = 1;
- int currMaxSequence = 1;
- int currMaxIndex = 0;
- int currSum = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- int currNum = arr[i];
- currSum += arr[i];
- for (int currI = i+1; currI < arr.Length; currI++)
- {
- if(currNum == 1 && currNum==arr[currI])
- {
- counter++;
- }
- else if(currNum == 1)
- {
- currMaxIndex = i;
- }
- else
- {
- break;
- }
- }
- if(currMaxSequence<counter)
- {
- currMaxSequence = counter;
- currMaxIndex = i;
- }
- }
- if((currMaxSequence>maxSequence) ||
- (currMaxSequence == maxSequence && leftMostIndex > currMaxIndex) ||
- (sum < currSum))
- {
- maxSequence = currMaxSequence;
- arrMax = arr.ToArray();
- leftMostIndex = currMaxIndex;
- sum = currSum;
- }
- //else if(currMaxSequence == maxSequence && leftMostIndex != currMaxIndex)
- //{
- // if(leftMostIndex>currMaxIndex)
- // {
- // leftMostIndex = currMaxIndex;
- // arrMax = arr.ToArray();
- // sum = currSum;
- // }
- //}
- //else if(currMaxSequence == maxSequence && leftMostIndex == currMaxIndex)
- //{
- // if(currSum>sum)
- // {
- // sum = currSum;
- // arrMax = arr.ToArray();
- // leftMostIndex = currMaxIndex;
- // }
- //}
- command = Console.ReadLine();
- }
- Console.WriteLine($"Best DNA sample {leftMostIndex+1} with sum: {sum}.");
- Console.WriteLine(string.Join(" ", arrMax));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement