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.
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is //in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public static class Program
- {
- public static void Main()
- {
- int dnaLength = int.Parse(Console.ReadLine());
- int sum =0;
- int length = 0;
- int row = 0;
- int currentRow=1;
- int startIndex=-1;
- int[] DNA = new int[dnaLength];
- while(true)
- {
- string input = Console.ReadLine();
- if(input == "clone")
- {
- break;
- }
- int[] currentDNA = input
- .Split('!')
- .Select(int.Parse)
- .ToArray();
- int currentSum = 0;
- for(int i = 0;i<currentDNA.Length;i++)
- {
- if(currentDNA[i]==1)
- {
- currentSum++;
- }
- }
- int currentLength=0;
- int currentStartIndex=-1;
- bool isTrue = false;
- for(int i=0;i<dnaLength;i++)
- {
- if(currentDNA[i]==1)
- {
- if(!isTrue)
- {
- currentStartIndex=i;
- }
- currentLength++;
- if (currentLength>length)
- {
- length = currentLength;
- startIndex=currentStartIndex;
- row=currentRow;
- sum=currentSum;
- DNA = currentDNA;
- }
- else if (currentLength==length)
- {
- if(currentStartIndex<startIndex)
- {
- length = currentLength;
- startIndex = currentStartIndex;
- row=currentRow;
- sum=currentSum;
- DNA = currentDNA;
- }
- else if(currentSum>sum)
- {
- length = currentLength;
- row=currentRow;
- sum=currentSum;
- DNA = currentDNA;
- }
- }
- else
- {
- currentStartIndex = -1;
- currentRow = 1;
- isTrue=false;
- }
- }
- }
- currentRow++;
- }
- Console.WriteLine($"Best DNA sample {row} with sum: {sum}.");
- Console.WriteLine(string.Join(" ", DNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement