Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- namespace KaminoFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int arrayLength = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- int[] DNKArray = new int[arrayLength];
- var dictDNKWithMaxSequenceLengthAndIndexAndSum = new Dictionary<string, List<int>>();
- int DNKCounter = 0;
- while (input != "Clone them!")
- {
- DNKArray = input.Split("!", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- string DNK = string.Join("", DNKArray);
- int sumDNK = DNKArray.Sum();
- DNKCounter++;
- Regex regexForSeqiencesWith1 = new Regex(@"1+");
- MatchCollection matchEverySequencesWith1 = regexForSeqiencesWith1.Matches(DNK);
- int maxSequencesLength = 0;
- int startIndexMaxSequence = 0;
- foreach (Match sequence in matchEverySequencesWith1)// to find the maxSequence and startIndexMaxSequence
- {
- int sequenceLength = sequence.Length;
- if (sequenceLength > maxSequencesLength)
- {
- maxSequencesLength = sequenceLength;
- startIndexMaxSequence = sequence.Index;
- }
- }
- if (dictDNKWithMaxSequenceLengthAndIndexAndSum.ContainsKey(DNK) == false)//save all DNK with maxSequencesLength, startIndexMaxSequence, sumDNK, DNKCounter
- {
- dictDNKWithMaxSequenceLengthAndIndexAndSum[DNK] = new List<int>();
- dictDNKWithMaxSequenceLengthAndIndexAndSum[DNK].Add(maxSequencesLength);//0
- dictDNKWithMaxSequenceLengthAndIndexAndSum[DNK].Add(startIndexMaxSequence);//1
- dictDNKWithMaxSequenceLengthAndIndexAndSum[DNK].Add(sumDNK);//2
- dictDNKWithMaxSequenceLengthAndIndexAndSum[DNK].Add(DNKCounter);//3
- }
- input = Console.ReadLine();
- }
- SortedAndPrintTheResult(dictDNKWithMaxSequenceLengthAndIndexAndSum);
- }
- private static void SortedAndPrintTheResult(Dictionary<string, List<int>> dictDNKWithMaxSequenceLengthAndIndexAndSum)
- {
- var sortedDictionary = dictDNKWithMaxSequenceLengthAndIndexAndSum.OrderByDescending(x => x.Value[0]).ThenBy(x => x.Value[1]).ThenByDescending(x => x.Value[2]);
- var bestDNK = sortedDictionary.Take(1).Select(x => x.Key).First();
- int bestDNKCounter = sortedDictionary.Take(1).Select(x => x.Value[3]).First();
- int bestDNKSum = sortedDictionary.Take(1).Select(x => x.Value[2]).First();
- Console.WriteLine($"Best DNA sample {bestDNKCounter} with sum: {bestDNKSum}.");
- Console.WriteLine(string.Join(" ", bestDNK.ToCharArray()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement