Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zvezvda
- {
- class Program
- {
- static void Main(string[] args)
- {
- int secMax = int.Parse(Console.ReadLine());
- int[] best = new int[secMax];
- string command = "";
- int seq = 0;
- int sum = 0;
- int index = -1;
- int seqBest = 0;
- int indexBest = 101;
- int sumBest = 0;
- int sampleCounter = 0;
- int sampleCounterBest = 0;
- while (true)
- {
- command = Console.ReadLine();
- if (command == "Clone them!")
- {
- break;
- }
- int[] line = command.Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int i = 0; i < line.Length; i++)
- {
- if ((i >= 0 && i < line.Length -1) && line[i] == 1 && line[i] == line[i + 1])
- {
- if (index > -1)
- {
- seq++;
- }
- else
- {
- seq++;
- index = i;
- }
- }
- sum += line[i];
- }
- for (int i = 0; i < line.Length; i++)
- {
- if (seq == 0 && line[i] == 1 && index < 0)
- {
- index = i;
- }
- }
- if (seq > seqBest)
- {
- best = line;
- seqBest = seq;
- indexBest = index;
- sumBest = sum;
- }
- else if (seq == seqBest && index < indexBest && seq > 0)
- {
- best = line;
- indexBest = index;
- sumBest = sum;
- }
- else if (seq == seqBest && index == indexBest && sum > sumBest)
- {
- best = line;
- indexBest = index;
- sumBest = sum;
- }
- else if (seq == 0 && index > -1 && index < indexBest)
- {
- best = line;
- indexBest = index;
- sumBest = sum;
- }
- else if (seq == 0 && index > -1 && index == indexBest && sum > sumBest)
- {
- best = line;
- indexBest = index;
- sumBest = sum;
- }
- sampleCounter++;
- if (line == best)
- {
- sampleCounterBest = sampleCounter;
- }
- seq = 0;
- sum = 0;
- index = -1;
- }
- if (sumBest == 0)
- {
- Console.WriteLine($"Best DNA sample {1} with sum: {0}.");
- Console.WriteLine(string.Join(" ", best));
- }
- else
- {
- Console.WriteLine($"Best DNA sample {sampleCounterBest} with sum: {sumBest}.");
- Console.WriteLine(string.Join(" ", best));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment