Advertisement
GabrielDas

Untitled

Mar 7th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P03CookingFactory
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. double bestQuality = 0;
  12. int bestLength = 0;
  13. int bestIndex = 0;
  14. double bestAverage = 0;
  15. double tempQuality = 0;
  16. int tempLength = 0;
  17. int tempIndex = 0;
  18. double tempAverage = 0;
  19.  
  20.  
  21. List<List<int>> batches = new List<List<int>>();
  22. List<int> tempList = new List<int>();
  23. List<int> numbersList = new List<int>();
  24. List<int> bestBatch = new List<int>();
  25. List<int> tempBestBatch = new List<int>();
  26.  
  27. while (true)
  28. {
  29. string command = Console.ReadLine();
  30.  
  31. if (command=="Bake It!")
  32. {
  33. break;
  34. }
  35.  
  36. string[] tokens = command.Split("#");
  37. int element = 0;
  38.  
  39.  
  40.  
  41. for(int i = 0; i < tokens.Length; i++)
  42. {
  43.  
  44. element = int.Parse(tokens[i]);
  45.  
  46. tempList.Add(element);
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53. batches.Add(tempList);
  54. tempList.Clear();
  55.  
  56.  
  57.  
  58. }
  59.  
  60. for (int i = 0; i < batches.Count; i++)
  61. {
  62. tempQuality = batches[i].Sum();
  63. tempLength = batches[i].Count();
  64. tempIndex = batches.IndexOf(batches[i]);
  65. tempAverage = tempQuality / tempLength;
  66.  
  67. if (tempQuality > bestQuality)
  68. {
  69. bestQuality = tempQuality;
  70. bestLength = tempLength;
  71. bestAverage = tempAverage;
  72. bestIndex = tempIndex; //!!
  73.  
  74. }
  75. else if (tempQuality == bestQuality)
  76. {
  77. if (tempAverage > bestAverage)
  78. {
  79. bestIndex = tempIndex;
  80. }
  81. else if (tempAverage == bestAverage)
  82. {
  83. if (tempLength < bestLength)
  84. {
  85. bestIndex = tempIndex;
  86. }
  87. }
  88. }
  89. }
  90.  
  91. Console.WriteLine($"Best Batch quality: {bestQuality}");
  92. Console.WriteLine(String.Join(" ", batches[bestIndex]));
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement