Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- namespace ConsoleApp74
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> samples = new Dictionary<string, int>();
- List<Sample> sampleList = new List<Sample>();
- int n = int.Parse(Console.ReadLine());
- int i = 0;
- while (true)
- {
- i++;
- string input = Console.ReadLine(); //1!0!1!1!0
- List<string> input2 = input.Split("!").ToList();
- List<string> input3 = new List<string>();
- if (input2.Count>n)
- {
- int p = 0;
- foreach (var inputt in input2)
- {
- p++;
- input3.Add(inputt);
- if (p==n)
- {
- break;
- }
- }
- input = string.Join("!", input3);
- }
- if (input == "Clone them!")
- {
- break;
- }
- string subsequence = "1!1";
- int index = input.IndexOf(subsequence);
- if (index<0)
- {
- continue;
- }
- else
- {
- Sample sample = new Sample(input,index,i);
- sampleList.Add(sample);
- samples.Add(sample.SampleText,sample.SampleIndex);
- }
- // dna1 : text -> 1!0!1!1 index-> 2
- // dna2 : text -> 1!1!0!1 index-> 0
- }
- int maxIndex = 0;
- List<string> dnas = new List<string>(); // 1!1!0!0 ; 1!1!0!1
- var sumDna = 0;
- var minKey = samples.Min(kvp => kvp.Value);
- // addva tova s nai malkoto indexche i ako sa dve dolu
- foreach (var sample in samples)
- {
- if (sample.Value == minKey && sample.Value!=-1)
- {
- dnas.Add(sample.Key);
- }
- else
- {
- continue;
- }
- }
- //addva suma
- foreach (var dna in dnas)
- {
- List<int> toSum = dna.Split("!").Select(int.Parse).ToList();
- foreach (var item in toSum)
- {
- sumDna += item;
- }
- foreach (var sample in sampleList)
- {
- if (dna == sample.SampleText)
- {
- sample.SampleSum = sumDna;
- break;
- }
- }
- sumDna = 0;
- }
- int SumFinal = 0;
- string keyFinal = "";
- int numberFinal = 0;
- foreach (var item in sampleList)
- {
- if (item.SampleSum>SumFinal)
- {
- SumFinal = item.SampleSum;
- keyFinal = item.SampleText;
- numberFinal = item.Number;
- }
- }
- /*Best DNA sample 2 with sum: 2
- 0 1 1 0 0*/
- Console.WriteLine($"Best DNA sample {numberFinal} with sum: {SumFinal}.");
- Console.WriteLine(string.Join(" ", keyFinal.Split("!").ToList()));
- }
- }
- }
- class Sample
- {
- public string SampleText;
- public int SampleIndex;
- public int SampleSum;
- public int Number;
- public Sample(string sampleText,int sampleIndex,int number)
- {
- this.SampleText = sampleText;
- this.SampleIndex = sampleIndex;
- this.Number = number;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement