Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SOFTUNI
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string completelyUselessTrashInput = Console.ReadLine(); //seriously who even needs that?
  12.             List<byte[]> dnaList = new List<byte[]>();
  13.  
  14.             while (true)
  15.             {
  16.                 string input = Console.ReadLine();
  17.                 if (input == "Clone them!") break;
  18.                 string[] inputSplitted = input.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.                 byte[] DNA = new byte[inputSplitted.Length];
  21.  
  22.                 for (int i = 0; i < inputSplitted.Length; i++)
  23.                 {
  24.                     DNA[i] = byte.Parse(inputSplitted[i]);
  25.                 }
  26.  
  27.                 dnaList.Add(DNA);
  28.             }
  29.  
  30.             byte[] bestDNAIndexes = GetBestDNA(dnaList);
  31.  
  32.             int sum = -1;
  33.             byte bestDNAIndex = 0;
  34.             byte[] bestDNAarr = null;
  35.  
  36.             foreach (byte index in bestDNAIndexes)
  37.             {
  38.                 int currsum = 0;
  39.                 byte[] currDNAarr = dnaList[index];
  40.  
  41.                 foreach (var number in currDNAarr)
  42.                 {
  43.                     currsum += number;
  44.                 }
  45.                 if (sum < currsum)
  46.                 {
  47.                     sum = currsum;
  48.                     bestDNAarr = currDNAarr;
  49.                     bestDNAIndex = index;
  50.                 }
  51.             }
  52.             if (bestDNAarr != null)
  53.             {
  54.                 Console.WriteLine($"Best DNA sample {bestDNAIndex + 1} with sum: {sum}.");
  55.                 Console.WriteLine(string.Join(" ", bestDNAarr));
  56.             }
  57.  
  58.         }
  59.  
  60.         static byte[] GetBestDNA(List<byte[]> DNAList)
  61.         {
  62.             Dictionary<byte, double> positionPower = new Dictionary<byte, double>();
  63.             for (byte i = 0; i < DNAList.Count; i++)
  64.             {
  65.                 byte[] input = DNAList[i];
  66.                 positionPower.Add(i, 0);
  67.                 byte prevInput = 0;
  68.                 for (byte j = 0; j < input.Length; j++)
  69.                 {
  70.                     if (input[j] == 1 && prevInput == 1)
  71.                     {
  72.                         positionPower[i] += input.Length - j;
  73.                     }
  74.                     prevInput = input[j];
  75.                 }
  76.  
  77.             }
  78.  
  79.             return positionPower.Where(x => x.Value == positionPower.Values.Max()).Select(y => y.Key).ToArray();
  80.  
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement