Advertisement
viraco4a

Camino

Jun 28th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace KaminoFactory
  6. {
  7. class Program
  8. {
  9. private static List<int[]> matrix;
  10. private static int length;
  11.  
  12. static void Main()
  13. {
  14. length = int.Parse(Console.ReadLine());
  15. string input = Console.ReadLine();
  16. Regex regex = new Regex(@"[0-9]");
  17. matrix = new List<int[]>();
  18. int row = 0;
  19. while (input != "Clone them!")
  20. {
  21. matrix.Add(new int[length]);
  22. MatchCollection matches = regex.Matches(input);
  23. int col = 0;
  24. foreach (Match match in matches)
  25. {
  26. matrix[row][col] = int.Parse(match.Value);
  27. col++;
  28. }
  29. row++;
  30. input = Console.ReadLine();
  31. }
  32.  
  33. int bestLength = 0;
  34. int bestSum = 0;
  35. int bestRow = 0;
  36. int bestCol = 0;
  37.  
  38. for (row = 0; row < matrix.Count; row++)
  39. {
  40. int bestCurrent = 0;
  41. int local = 0;
  42. int localSum = 0;
  43. int currentCol = 0;
  44. for (int col = 0; col < length; col++)
  45. {
  46. localSum += matrix[row][col];
  47. if (matrix[row][col] == 1)
  48. {
  49. local++;
  50. if (local > bestCurrent)
  51. {
  52. bestCurrent = local;
  53. if (col != 0)
  54. {
  55. currentCol = col - 1;
  56. }
  57. }
  58. }
  59. else
  60. {
  61. local = 0;
  62. }
  63. }
  64. if (bestCurrent > bestLength)
  65. {
  66. bestLength = bestCurrent;
  67. bestRow = row;
  68. bestSum = localSum;
  69. bestCol = currentCol;
  70. continue;
  71. }
  72. if (bestCurrent == bestLength && currentCol < bestCol)
  73. {
  74. bestLength = bestCurrent;
  75. bestRow = row;
  76. bestSum = localSum;
  77. bestCol = currentCol;
  78. continue;
  79. }
  80. if (bestCurrent == bestLength && currentCol == bestCol && localSum > bestSum)
  81. {
  82. bestLength = bestCurrent;
  83. bestRow = row;
  84. bestSum = localSum;
  85. bestCol = currentCol;
  86. continue;
  87. }
  88. }
  89. Console.WriteLine($"Best DNA sample {bestRow + 1} with sum: {bestSum}.");
  90. Console.WriteLine(string.Join(" ", matrix[bestRow]));
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement