Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace KaminoFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int len = int.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- List<string> values = new List<string>();
- int count = 0;
- while (command != "Clone them!")
- {
- count++;
- string numbers = string.Join("", command.Split(new[] { '!' }, StringSplitOptions.RemoveEmptyEntries).ToArray());
- List<string> nums = numbers.Split(new[] { '0' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- if (nums.Count == 0)
- {
- command = Console.ReadLine();
- continue;
- }
- int length = nums.Max(x => x.Length);
- int index = numbers.IndexOf(new string('1', length));
- int sum = numbers.ToCharArray().Sum(x => int.Parse(x.ToString()));
- values.Add(length + " " + index + " " + sum + " " + numbers + " " + count);
- command = Console.ReadLine();
- }
- if (values.Count == 0)
- {
- Console.WriteLine($"Best DNA sample 1 with sum: 0.");
- Console.WriteLine($"{string.Join(" ", new string('0', len).ToCharArray())}");
- return;
- }
- var results = values
- .OrderByDescending(x => x.Split(' ')[0])
- .ThenBy(x => x.Split(' ')[1])
- .ThenByDescending(x => x.Split(' ')[2]).ToList();
- string element = results.First();
- Console.WriteLine($"Best DNA sample {element.Split(' ')[4]} with sum: {element.Split(' ')[2]}.");
- Console.WriteLine($"{string.Join(" ", element.Split(' ')[3].ToCharArray())}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement