Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
- namespace CSharp_Shell
- {
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- public static class Program
- {
- public static void Main()
- {
- var dnaLength=int.Parse(Console.ReadLine());
- var DNA = new int[dnaLength];
- var row = 0;
- var sum = 0;
- while(true)
- {
- var input = Console.ReadLine();
- if(input=="end")
- {
- break;
- }
- var currentDNA=input.Split('!',StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- for(int i=0; i<currentDNA.Length;i++)
- {
- sum+=currentDNA[i];
- }
- var length=0;
- var currLength = 0;
- var currRow=1;
- var index=-1;
- var currIndex=-1;
- //var currSum=0;
- for(int i=0;i<DNA.Length;i++)
- {
- var currSum=0;
- if(currentDNA[i]==1)
- {
- currLength++;
- currIndex=i;
- currSum=sum;
- if(currLength>length)
- {
- length=currLength;
- row=currRow;
- index=currIndex;
- DNA=currentDNA;
- }
- else if(currLength==length)
- {
- if(currIndex<index)
- {
- length=currLength;
- row=currRow;
- index=currIndex;
- DNA=currentDNA;
- }
- else if(currIndex==index)
- {
- if(currSum>sum)
- {
- length=currLength;
- row=currRow;
- index=currIndex;
- DNA=currentDNA;
- }
- }
- }
- }
- else
- {
- currLength=0;
- currRow=1;
- currIndex=-1;
- currSum=0;
- //sum=0;
- }
- currRow++;
- }
- }
- Console.WriteLine($"Best DNA sample {row} with sum: {sum}.");
- Console.WriteLine(string.Join(" ", DNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement