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 length = 0;
- int sum = 0;
- int startIndex = 0;
- int row = 0;
- int currentRow = 1;
- bool isFound = false;
- int[] DNA = new int[dnaLength];
- while(true)
- {
- string line = Console.ReadLine();
- if(line == "clone")
- {
- break;
- }
- int[] currentDNA = line
- .Split('!')
- .Select(int.Parse)
- .ToArray();
- int currentStartIndex = -1;
- int currentLength = 0;
- int currentSum = 0;
- for(int i=0;i<currentDNA.Length;i++)
- {
- if(currentDNA[i]==1)
- {
- currentSum++;
- }
- }
- for(int i=0; i<currentDNA.Length; i++)
- {
- if(currentDNA[i] == 1)
- {
- if(!isFound)
- {
- currentStartIndex = i;
- }
- currentLength++;
- if(currentLength>length)
- {
- length = currentLength;
- startIndex = currentStartIndex;
- sum = currentSum;
- row = currentRow;
- DNA = currentDNA;
- }
- else if(currentLength==length)
- {
- if(currentStartIndex<startIndex)
- {
- length = currentLength;
- startIndex = currentStartIndex;
- sum = currentSum;
- row = currentRow;
- DNA = currentDNA;
- }
- else if(currentSum>sum)
- {
- length = currentLength;
- startIndex = currentStartIndex;
- sum = currentSum;
- row = currentRow;
- DNA = currentDNA;
- }
- }
- }
- else
- {
- isFound = false;
- currentStartIndex = -1;
- //currentSum = 0;
- currentLength = 0;
- //currentRow = 1;
- }
- }
- currentRow++;
- }
- Console.WriteLine($"row {row} sum {sum}.");
- Console.WriteLine(string.Join(" ", DNA));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement