Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _02._Kamino_Factory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Regex reg = new Regex(@"1+");
- int leftMostIndex = int.MaxValue;
- int bestSequenceLength = 0;
- int bestSum = 0;
- int bestSampleIndex = 0;
- char[] bestSample = new char[n];
- int sampleIndex = 1;
- string input = string.Empty;
- while ((input = Console.ReadLine().Replace("!", "")) != "Clone them")
- {
- string currentBestSequence = string.Empty;
- foreach (Match match in reg.Matches(input))
- {
- if (currentBestSequence.Length < match.Groups[0].Value.Length)
- {
- currentBestSequence = match.Groups[0].Value;
- }
- }
- bool foundNewBestSequence = false;
- if (bestSequenceLength < currentBestSequence.Length)
- {
- foundNewBestSequence = true;
- }
- else if (bestSequenceLength == currentBestSequence.Length)
- {
- if (leftMostIndex > input.IndexOf(currentBestSequence))
- {
- foundNewBestSequence = true;
- }
- else if (bestSum < input.Replace("0", "").Length)
- {
- foundNewBestSequence = true;
- }
- }
- if (foundNewBestSequence)
- {
- bestSequenceLength = currentBestSequence.Length;
- leftMostIndex = input.IndexOf(currentBestSequence);
- bestSampleIndex = sampleIndex;
- bestSum = input.Replace("0", "").Length;
- bestSample = input.ToCharArray();
- }
- sampleIndex++;
- }
- Console.WriteLine($"Best DNA sample {bestSampleIndex} with sum: {bestSum}.");
- Console.WriteLine(string.Join(" ", bestSample));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement