Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- int DNALength = int.Parse(Console.ReadLine());
- int sum=0;
- int bestSum=0;
- int length =0;
- int bestLength =0;
- int startIndex =-1;
- int bestIndex = -1;
- int line =0;
- int bestLine=0;
- int[] bestDNA = new int [DNALength];
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Clone them!")
- {
- break;
- }
- int [] currDNA = command.Split(new [] {'!'},StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- startIndex =-1;
- length =0;
- sum=0;
- line++;
- for (int i=0; i<currDNA.Length; i++)
- {
- if (currDNA[i]==1)
- {
- sum++;
- }
- }
- for (int i=0; i<currDNA.Length; i++)
- {
- if (currDNA[i]==1)
- {
- length++;
- if (length==1)
- {
- startIndex=i;
- }
- }
- else if (currDNA[i]==0)
- {
- length=0;
- }
- if (length>bestLength)
- {
- bestLength = length;
- bestSum = sum;
- bestLine=line;
- bestDNA=currDNA;
- bestIndex=startIndex;
- }
- if (length==bestLength)
- {
- if (startIndex<bestIndex)
- {
- bestLength = length;
- bestSum = sum;
- bestLine=line;
- bestDNA=currDNA;
- bestIndex=startIndex;
- }
- else if (startIndex==bestIndex)
- {
- if (sum>bestSum)
- {
- bestLength = length;
- bestSum = sum;
- bestLine=line;
- bestDNA=currDNA;
- }
- }
- }
- }
- }
- if (bestLength==0)
- {
- bestLine=1;
- Console.WriteLine("Best DNA sample {0} with sum: {1}.",bestLine,bestSum);
- Console.WriteLine(string.Join(" ",bestDNA));
- return;
- }
- Console.WriteLine("Best DNA sample {0} with sum: {1}.",bestLine,bestSum);
- Console.WriteLine(string.Join(" ",bestDNA));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement