bullit3189

Baking Factory TF MidExam 27Oct18

Jan 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _03BakingFactory
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. double currQuality = 0;
  12. double bestQuality = double.MinValue;
  13. double currAvg = 0;
  14. double bestAvg = double.MinValue;
  15. int currLen = -1;
  16. int bestLen = int.MaxValue;
  17.  
  18. List<int> bestBatch = new List<int>();
  19.  
  20. while (true)
  21. {
  22. string command = Console.ReadLine();
  23.  
  24. if (command == "Bake It!")
  25. {
  26. break;
  27. }
  28. currQuality = 0;
  29. currAvg = 0;
  30.  
  31. int[] currBatch = command.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  32.  
  33. for (int i = 0; i < currBatch.Length; i++)
  34. {
  35. currQuality += currBatch[i];
  36. }
  37. currAvg = currQuality / currBatch.Length;
  38. currLen = currBatch.Length;
  39.  
  40. if (currQuality > bestQuality)
  41. {
  42. bestQuality = currQuality;
  43. bestBatch.Clear();
  44. bestBatch.AddRange(currBatch);
  45. bestAvg = currAvg;
  46. bestLen = currLen;
  47. }
  48.  
  49. else if (currQuality == bestQuality)
  50. {
  51. if (currAvg > bestAvg)
  52. {
  53. bestQuality = currQuality;
  54. bestBatch.Clear();
  55. bestBatch.AddRange(currBatch);
  56. }
  57. else if (currAvg == bestAvg)
  58. {
  59. if (currLen < bestLen)
  60. {
  61. bestQuality = currQuality;
  62. bestBatch.Clear();
  63. bestBatch.AddRange(currBatch);
  64. }
  65. }
  66. }
  67.  
  68. }
  69.  
  70.  
  71. Console.WriteLine("Best Batch quality: {0}", bestQuality);
  72. Console.WriteLine(string.Join(" ", bestBatch));
  73. }
  74. }
  75. }
Add Comment
Please, Sign In to add comment