Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp74
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Dictionary<string, int> samples = new Dictionary<string, int>();
  13. List<Sample> sampleList = new List<Sample>();
  14.  
  15. int n = int.Parse(Console.ReadLine());
  16. int i = 0;
  17. while (true)
  18. {
  19. i++;
  20. string input = Console.ReadLine(); //1!0!1!1!0
  21. List<string> input2 = input.Split("!").ToList();
  22. List<string> input3 = new List<string>();
  23. if (input2.Count>n)
  24. {
  25. int p = 0;
  26. foreach (var inputt in input2)
  27. {
  28. p++;
  29. input3.Add(inputt);
  30. if (p==n)
  31. {
  32. break;
  33. }
  34.  
  35. }
  36. input = string.Join("!", input3);
  37. }
  38.  
  39.  
  40. if (input == "Clone them!")
  41. {
  42. break;
  43. }
  44. string subsequence = "1!1";
  45.  
  46. int index = input.IndexOf(subsequence);
  47. if (index<0)
  48. {
  49. continue;
  50. }
  51. else
  52. {
  53. Sample sample = new Sample(input,index,i);
  54. sampleList.Add(sample);
  55. samples.Add(sample.SampleText,sample.SampleIndex);
  56.  
  57. }
  58. // dna1 : text -> 1!0!1!1 index-> 2
  59. // dna2 : text -> 1!1!0!1 index-> 0
  60.  
  61. }
  62. int maxIndex = 0;
  63. List<string> dnas = new List<string>(); // 1!1!0!0 ; 1!1!0!1
  64.  
  65. var sumDna = 0;
  66. var minKey = samples.Min(kvp => kvp.Value);
  67.  
  68. // addva tova s nai malkoto indexche i ako sa dve dolu
  69. foreach (var sample in samples)
  70. {
  71. if (sample.Value == minKey && sample.Value!=-1)
  72. {
  73. dnas.Add(sample.Key);
  74. }
  75. else
  76. {
  77. continue;
  78. }
  79. }
  80. //addva suma
  81. foreach (var dna in dnas)
  82. {
  83. List<int> toSum = dna.Split("!").Select(int.Parse).ToList();
  84. foreach (var item in toSum)
  85. {
  86. sumDna += item;
  87. }
  88. foreach (var sample in sampleList)
  89. {
  90. if (dna == sample.SampleText)
  91. {
  92. sample.SampleSum = sumDna;
  93. break;
  94. }
  95.  
  96. }
  97. sumDna = 0;
  98. }
  99. int SumFinal = 0;
  100. string keyFinal = "";
  101. int numberFinal = 0;
  102. foreach (var item in sampleList)
  103. {
  104. if (item.SampleSum>SumFinal)
  105. {
  106. SumFinal = item.SampleSum;
  107. keyFinal = item.SampleText;
  108. numberFinal = item.Number;
  109. }
  110.  
  111. }
  112. /*Best DNA sample 2 with sum: 2
  113. 0 1 1 0 0*/
  114. Console.WriteLine($"Best DNA sample {numberFinal} with sum: {SumFinal}.");
  115.  
  116. Console.WriteLine(string.Join(" ", keyFinal.Split("!").ToList()));
  117.  
  118.  
  119.  
  120. }
  121.  
  122. }
  123. }
  124. class Sample
  125. {
  126. public string SampleText;
  127. public int SampleIndex;
  128. public int SampleSum;
  129. public int Number;
  130.  
  131. public Sample(string sampleText,int sampleIndex,int number)
  132. {
  133. this.SampleText = sampleText;
  134. this.SampleIndex = sampleIndex;
  135. this.Number = number;
  136.  
  137. }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement