Advertisement
Guest User

Untitled

a guest
Oct 24th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace KaminoFactory
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int len = int.Parse(Console.ReadLine());
  12. string command = Console.ReadLine();
  13. List<string> values = new List<string>();
  14. int count = 0;
  15. while (command != "Clone them!")
  16. {
  17. count++;
  18. string numbers = string.Join("", command.Split(new[] { '!' }, StringSplitOptions.RemoveEmptyEntries).ToArray());
  19. List<string> nums = numbers.Split(new[] { '0' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  20. if (nums.Count == 0)
  21. {
  22. command = Console.ReadLine();
  23. continue;
  24. }
  25. int length = nums.Max(x => x.Length);
  26. int index = numbers.IndexOf(new string('1', length));
  27. int sum = numbers.ToCharArray().Sum(x => int.Parse(x.ToString()));
  28. values.Add(length + " " + index + " " + sum + " " + numbers + " " + count);
  29. command = Console.ReadLine();
  30. }
  31. if (values.Count == 0)
  32. {
  33. Console.WriteLine($"Best DNA sample 1 with sum: 0.");
  34. Console.WriteLine($"{string.Join(" ", new string('0', len).ToCharArray())}");
  35. return;
  36. }
  37. var results = values
  38. .OrderByDescending(x => x.Split(' ')[0])
  39. .ThenBy(x => x.Split(' ')[1])
  40. .ThenByDescending(x => x.Split(' ')[2]).ToList();
  41. string element = results.First();
  42. Console.WriteLine($"Best DNA sample {element.Split(' ')[4]} with sum: {element.Split(' ')[2]}.");
  43. Console.WriteLine($"{string.Join(" ", element.Split(' ')[3].ToCharArray())}");
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement