Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace KaminoFactory
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int DNALength = int.Parse(Console.ReadLine());
  11. string DNASequence = Console.ReadLine();
  12. int currentLength = 1;
  13. int bestLength = 0;
  14. int bestStartPosition = -1;
  15. int bestSequenceIndex = 0;
  16. int k = 0;
  17. int currentStartPosition = 0;
  18. int currentSequenceIndex = 0;
  19. int currentSum = 0;
  20. int bestSum = 0;
  21. int[] bestDNA = new int[DNASequence.Length];
  22. while (DNASequence != "Clone them!")
  23. {
  24. int[] currentDNA = DNASequence
  25. .Split('!', StringSplitOptions.RemoveEmptyEntries)
  26. .Select(int.Parse)
  27. .ToArray();
  28. currentSequenceIndex += 1;
  29. currentSum = currentDNA.Sum();
  30. if (currentSum > bestSum)
  31. {
  32. bestSum = currentSum;
  33. }
  34. for (int i = 0; i < currentDNA.Length - 1; i++)
  35. {
  36. if (currentDNA[i] == currentDNA[i + 1] && currentDNA[i] != 0)
  37. {
  38. if (k == 0)
  39. {
  40. currentStartPosition = i;
  41. }
  42. currentLength += 1;
  43. k += 1;
  44. }
  45. else
  46. {
  47. currentLength = 1;
  48. k = 0;
  49. }
  50.  
  51. if (currentLength > bestLength)
  52. {
  53. bestLength = currentLength;
  54. bestStartPosition = currentStartPosition;
  55. bestSequenceIndex = currentSequenceIndex;
  56. bestSum = currentSum;
  57. bestDNA = currentDNA;
  58. }
  59. else if (currentLength == bestLength)
  60. {
  61. if (currentStartPosition < bestStartPosition)
  62. {
  63. bestLength = currentLength;
  64. bestSum = currentSum;
  65. bestStartPosition = currentStartPosition;
  66. bestSequenceIndex = currentSequenceIndex;
  67. bestDNA = currentDNA;
  68.  
  69. }
  70. else if (currentStartPosition == bestStartPosition)
  71. {
  72. if (currentSum > bestSum)
  73. {
  74. bestSum = currentSum;
  75. bestStartPosition = currentStartPosition;
  76. bestSequenceIndex = currentSequenceIndex;
  77. bestLength = currentLength;
  78. bestDNA = currentDNA;
  79. }
  80. }
  81. }
  82. }
  83. DNASequence = Console.ReadLine();
  84. }
  85. Console.WriteLine($"Best DNA sample {bestSequenceIndex} with sum: {bestSum}.");
  86. Console.WriteLine(string.Join(' ', bestDNA));
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement