Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Cooking_factory
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string command = Console.ReadLine();
  12. int avQuality = 0;
  13. int maxQuality = int.MinValue;
  14. int maxAvQuality = int.MinValue;
  15. int bestBatchIndex = -1 ;
  16. int batchIndex = -1; ;
  17. int minLenght = 0;
  18. List<string> batches = new List<string>();
  19.  
  20. while (command!="Bake it!")
  21. {
  22. int quality = 0;
  23. batchIndex++;
  24. batches.Add(command);
  25. string[] batchNumbers = command.Split('#').ToArray();
  26. for (int i = 0; i < batchNumbers.Length; i++)
  27. {
  28. quality += int.Parse(batchNumbers[i]);
  29. }
  30. avQuality = quality / batchNumbers.Length;
  31. if (quality>maxQuality)
  32. {
  33. maxQuality = quality;
  34. bestBatchIndex = batchIndex;
  35. minLenght = batchNumbers.Length;
  36. maxAvQuality = avQuality;
  37. }
  38. else if(quality==maxQuality)
  39. {
  40. if(avQuality>maxAvQuality)
  41. {
  42. maxAvQuality = avQuality;
  43. bestBatchIndex = batchIndex;
  44. minLenght = batchNumbers.Length;
  45. }
  46. else if(avQuality==maxAvQuality)
  47. {
  48. if(batchNumbers.Length<minLenght)
  49. {
  50. maxAvQuality = avQuality;
  51. bestBatchIndex = batchIndex;
  52. minLenght = batchNumbers.Length;
  53. }
  54. }
  55. }
  56.  
  57. command = Console.ReadLine();
  58. }
  59. string[] bestBatchNumbers = batches[bestBatchIndex].Split('#').ToArray();
  60. Console.WriteLine($"Best Batch quality: {maxQuality}");
  61. Console.WriteLine(string.Join(" ",bestBatchNumbers));
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement