Again_89

09. Kamino Factory

Dec 6th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace zvezvda
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int secMax = int.Parse(Console.ReadLine());
  14.  
  15. int[] best = new int[secMax];
  16.  
  17. string command = "";
  18.  
  19. int seq = 0;
  20. int sum = 0;
  21. int index = -1;
  22.  
  23. int seqBest = 0;
  24. int indexBest = 101;
  25. int sumBest = 0;
  26.  
  27. int sampleCounter = 0;
  28. int sampleCounterBest = 0;
  29.  
  30. while (true)
  31. {
  32. command = Console.ReadLine();
  33.  
  34. if (command == "Clone them!")
  35. {
  36. break;
  37. }
  38.  
  39. int[] line = command.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  40.  
  41. for (int i = 0; i < line.Length; i++)
  42. {
  43. if ((i >= 0 && i < line.Length -1) && line[i] == 1 && line[i] == line[i + 1])
  44. {
  45. if (index > -1)
  46. {
  47. seq++;
  48. }
  49. else
  50. {
  51. seq++;
  52. index = i;
  53. }
  54. }
  55.  
  56. sum += line[i];
  57. }
  58.  
  59. for (int i = 0; i < line.Length; i++)
  60. {
  61. if (seq == 0 && line[i] == 1 && index < 0)
  62. {
  63. index = i;
  64. }
  65.  
  66. }
  67.  
  68. if (seq > seqBest)
  69. {
  70. best = line;
  71. seqBest = seq;
  72. indexBest = index;
  73. sumBest = sum;
  74. }
  75. else if (seq == seqBest && index < indexBest && seq > 0)
  76. {
  77. best = line;
  78. indexBest = index;
  79. sumBest = sum;
  80. }
  81. else if (seq == seqBest && index == indexBest && sum > sumBest)
  82. {
  83. best = line;
  84. indexBest = index;
  85. sumBest = sum;
  86.  
  87. }
  88. else if (seq == 0 && index > -1 && index < indexBest)
  89. {
  90. best = line;
  91. indexBest = index;
  92. sumBest = sum;
  93. }
  94. else if (seq == 0 && index > -1 && index == indexBest && sum > sumBest)
  95. {
  96. best = line;
  97. indexBest = index;
  98. sumBest = sum;
  99. }
  100.  
  101. sampleCounter++;
  102. if (line == best)
  103. {
  104. sampleCounterBest = sampleCounter;
  105. }
  106.  
  107. seq = 0;
  108. sum = 0;
  109. index = -1;
  110. }
  111.  
  112. if (sumBest == 0)
  113. {
  114. Console.WriteLine($"Best DNA sample {1} with sum: {0}.");
  115. Console.WriteLine(string.Join(" ", best));
  116. }
  117. else
  118. {
  119. Console.WriteLine($"Best DNA sample {sampleCounterBest} with sum: {sumBest}.");
  120. Console.WriteLine(string.Join(" ", best));
  121. }
  122.  
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment