Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
1,317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _09._Kamino_Factory
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. int dnaLength = int.Parse(Console.ReadLine());
  11.  
  12. int[] bestSample = new int[dnaLength];
  13. int leftmostIndex = dnaLength;
  14. int bestSampleSequenseLenght = 0;
  15. int bestSampleSum = 0;
  16. int bestSampleNumber = 1;
  17.  
  18. string command = Console.ReadLine();
  19. int sampleNum = 0;
  20.  
  21. while (command != "Clone them!")
  22. {
  23. int[] currentSample = command.Split("!".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  24. .Select(int.Parse)
  25. .ToArray();
  26.  
  27. sampleNum++;
  28.  
  29. int currentSequenceLenght = 0;
  30. int previousSequenceLenght = 0;
  31. int currentLongestSequence = 0;
  32.  
  33. int leftmostIndexInCurrentArray = dnaLength;
  34.  
  35. int currentSampleSum = 0;
  36.  
  37. for (int i = 0; i < currentSample.Length; i++)
  38. {
  39. if (currentSample[i] == 1)
  40. {
  41. currentSequenceLenght++;
  42. currentSampleSum++;
  43. }
  44. else
  45. {
  46. previousSequenceLenght = currentSequenceLenght;
  47. currentSequenceLenght = 0;
  48. }
  49.  
  50. if (currentSequenceLenght > previousSequenceLenght)
  51. {
  52. currentLongestSequence = currentSequenceLenght;
  53. leftmostIndexInCurrentArray = i - currentSequenceLenght + 1;
  54. }
  55. }
  56.  
  57. if (currentLongestSequence > bestSampleSequenseLenght)
  58. {
  59. bestSampleSequenseLenght = currentLongestSequence;
  60. leftmostIndex = leftmostIndexInCurrentArray;
  61. bestSample = currentSample;
  62. bestSampleNumber = sampleNum;
  63. bestSampleSum = currentSampleSum;
  64. }
  65. else if (currentLongestSequence == bestSampleSequenseLenght)
  66. {
  67. if (leftmostIndexInCurrentArray < leftmostIndex)
  68. {
  69. leftmostIndex = leftmostIndexInCurrentArray;
  70. bestSampleSum = currentSampleSum;
  71. bestSample = currentSample;
  72. bestSampleNumber = sampleNum;
  73. }
  74. else if (leftmostIndex == leftmostIndexInCurrentArray)
  75. {
  76. if (currentSampleSum > bestSampleSum)
  77. {
  78. bestSampleSum = currentSampleSum;
  79. bestSample = currentSample;
  80. bestSampleNumber = sampleNum;
  81. }
  82. }
  83. }
  84.  
  85. command = Console.ReadLine();
  86. }
  87.  
  88. Console.WriteLine($"Best DNA sample {bestSampleNumber} with sum: {bestSampleSum}.");
  89. Console.WriteLine(string.Join(" ", bestSample));
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement