Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace KaminoFactory
- {
- class Program
- {
- private static List<int[]> matrix;
- private static int length;
- static void Main()
- {
- length = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- Regex regex = new Regex(@"[0-9]");
- matrix = new List<int[]>();
- int row = 0;
- while (input != "Clone them!")
- {
- matrix.Add(new int[length]);
- MatchCollection matches = regex.Matches(input);
- int col = 0;
- foreach (Match match in matches)
- {
- matrix[row][col] = int.Parse(match.Value);
- col++;
- }
- row++;
- input = Console.ReadLine();
- }
- int bestLength = 0;
- int bestSum = 0;
- int bestRow = 0;
- int bestCol = 0;
- for (row = 0; row < matrix.Count; row++)
- {
- int bestCurrent = 0;
- int local = 0;
- int localSum = 0;
- int currentCol = 0;
- for (int col = 0; col < length; col++)
- {
- localSum += matrix[row][col];
- if (matrix[row][col] == 1)
- {
- local++;
- if (local > bestCurrent)
- {
- bestCurrent = local;
- if (col != 0)
- {
- currentCol = col - 1;
- }
- }
- }
- else
- {
- local = 0;
- }
- }
- if (bestCurrent > bestLength)
- {
- bestLength = bestCurrent;
- bestRow = row;
- bestSum = localSum;
- bestCol = currentCol;
- continue;
- }
- if (bestCurrent == bestLength && currentCol < bestCol)
- {
- bestLength = bestCurrent;
- bestRow = row;
- bestSum = localSum;
- bestCol = currentCol;
- continue;
- }
- if (bestCurrent == bestLength && currentCol == bestCol && localSum > bestSum)
- {
- bestLength = bestCurrent;
- bestRow = row;
- bestSum = localSum;
- bestCol = currentCol;
- continue;
- }
- }
- Console.WriteLine($"Best DNA sample {bestRow + 1} with sum: {bestSum}.");
- Console.WriteLine(string.Join(" ", matrix[bestRow]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement