Again_89

3та задача от демо изпит

Mar 2nd, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace _3.CookingFactory
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. int bestTotalQuality = -10000; // тук е първата грешка!
  12. double bestAverage = 0;
  13. string bestLine = "";
  14. int bestLength = int.MaxValue;
  15. int totalCurrentQuality = 0;
  16. int currentLength = 0;
  17. double currentAverage = 0;
  18. while (true)
  19. {
  20. string line = Console.ReadLine();
  21. if (line == "Bake It!")
  22. {
  23. break;
  24. }
  25. int[] qualitiesOfCurrentBread = line.Split('#').Select(int.Parse).ToArray();
  26. totalCurrentQuality = 0;
  27. currentLength = qualitiesOfCurrentBread.Length;
  28.  
  29. // 5#3#2 total: 10; average:3; lenght:3 --> best element
  30. //10#2#-2#1#-1 total: 10; average:2; lenght:5
  31. //4#2#1 total:7; average: 2; lenght: 3
  32. //Bake It!
  33. for (int i = 0; i < qualitiesOfCurrentBread.Length; i++)
  34. {
  35. totalCurrentQuality += qualitiesOfCurrentBread[i];
  36. }
  37.  
  38. currentAverage = totalCurrentQuality / (qualitiesOfCurrentBread.Length);
  39.  
  40. if (totalCurrentQuality > bestTotalQuality)
  41. {
  42. bestTotalQuality = totalCurrentQuality;
  43. bestAverage = currentAverage;
  44. bestLine = line;
  45. bestLength = currentLength; //тук трябва да е така!
  46. }
  47. else if (totalCurrentQuality == bestTotalQuality && currentAverage > bestAverage) //тук трябва да е такава проверката!
  48. {
  49. //if (currentAverage > bestAverage)
  50. //{
  51. bestAverage = currentAverage;
  52. bestTotalQuality = totalCurrentQuality;
  53. bestLine = line;
  54. //}
  55. bestLength = currentLength;//тук трябва да е така!
  56. }
  57. else if ((totalCurrentQuality == bestTotalQuality) && (currentAverage == bestAverage))
  58. {
  59. if (currentLength < bestLength)
  60. {
  61. bestTotalQuality = totalCurrentQuality;
  62. bestLine = line;
  63. bestLength = currentLength;
  64. }
  65. }
  66. }
  67. Console.WriteLine($"Best Batch quality: {bestTotalQuality}");
  68. Console.WriteLine(bestLine.Replace("#", " "));
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment