Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SOFTUNI
- {
- class Program
- {
- static void Main(string[] args)
- {
- string completelyUselessTrashInput = Console.ReadLine(); //seriously who even needs that?
- List<byte[]> dnaList = new List<byte[]>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Clone them!") break;
- string[] inputSplitted = input.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries);
- byte[] DNA = new byte[inputSplitted.Length];
- for (int i = 0; i < inputSplitted.Length; i++)
- {
- DNA[i] = byte.Parse(inputSplitted[i]);
- }
- dnaList.Add(DNA);
- }
- byte[] bestDNAIndexes = GetBestDNA(dnaList);
- int sum = -1;
- byte bestDNAIndex = 0;
- byte[] bestDNAarr = null;
- foreach (byte index in bestDNAIndexes)
- {
- int currsum = 0;
- byte[] currDNAarr = dnaList[index];
- foreach (var number in currDNAarr)
- {
- currsum += number;
- }
- if (sum < currsum)
- {
- sum = currsum;
- bestDNAarr = currDNAarr;
- bestDNAIndex = index;
- }
- }
- if (bestDNAarr != null)
- {
- Console.WriteLine($"Best DNA sample {bestDNAIndex + 1} with sum: {sum}.");
- Console.WriteLine(string.Join(" ", bestDNAarr));
- }
- }
- static byte[] GetBestDNA(List<byte[]> DNAList)
- {
- Dictionary<byte, double> positionPower = new Dictionary<byte, double>();
- for (byte i = 0; i < DNAList.Count; i++)
- {
- byte[] input = DNAList[i];
- positionPower.Add(i, 0);
- byte prevInput = 0;
- for (byte j = 0; j < input.Length; j++)
- {
- if (input[j] == 1 && prevInput == 1)
- {
- positionPower[i] += input.Length - j;
- }
- prevInput = input[j];
- }
- }
- return positionPower.Where(x => x.Value == positionPower.Values.Max()).Select(y => y.Key).ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement