bullit3189

Kamino Factory - Edited

Feb 16th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 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 input = Console.ReadLine();
  12.  
  13. int DNACount = 0;
  14. int bestLength = 0;
  15. int bestStartIndex = -1;
  16. int bestSum = 0;
  17. int bestDNACount = -1;
  18.  
  19. int[] bestDNA = new int[DNALength];
  20.  
  21. while (input != "Clone them!")
  22. {
  23. int[] currentDNA = input
  24. .Split('!', StringSplitOptions.RemoveEmptyEntries)
  25. .Select(int.Parse)
  26. .ToArray();
  27. DNACount += 1;
  28. int currentLength = 0;
  29. int currentSum = 0;
  30. int currentStartIndex = -1;
  31.  
  32. for (int i = 0; i < currentDNA.Length; i++)
  33. {
  34. if (currentDNA[i] == 1)
  35. {
  36. currentSum += 1;
  37. }
  38. }
  39.  
  40. for (int i = 0; i < currentDNA.Length; i++)
  41. {
  42. if (currentDNA[i] == 1)
  43. {
  44. currentLength += 1;
  45. if (currentLength == 1)
  46. {
  47. currentStartIndex = i;
  48. }
  49.  
  50. }
  51. else
  52. {
  53. currentLength = 0;
  54. }
  55.  
  56. if (currentLength > bestLength)
  57. {
  58. bestLength = currentLength;
  59. bestStartIndex = currentStartIndex;
  60. bestSum = currentSum;
  61. bestDNA = currentDNA;
  62. bestDNACount = DNACount;
  63. }
  64. else if (currentLength == bestLength && currentStartIndex < bestStartIndex)
  65. {
  66. bestStartIndex = currentStartIndex;
  67. bestSum = currentSum;
  68. bestDNA = currentDNA;
  69. bestDNACount = DNACount;
  70. }
  71. else if (currentLength == bestLength &&
  72. currentStartIndex == bestStartIndex && currentSum > bestSum)
  73. {
  74. bestDNA = currentDNA;
  75. bestDNACount = DNACount;
  76. bestSum = currentSum;
  77. }
  78. }
  79.  
  80. input = Console.ReadLine();
  81. }
  82. if (bestLength ==0)
  83. {
  84. bestDNACount =1;
  85. }
  86.  
  87. Console.WriteLine($"Best DNA sample {bestDNACount} with sum: {bestSum}.");
  88. Console.WriteLine($"{string.Join(' ', bestDNA)}");
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment