Guest User

Untitled

a guest
Jun 25th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. namespace _06.Winecraft
  2. {
  3. using System;
  4. using System.Linq;
  5.  
  6. public class Winecraft
  7. {
  8. public static void Main()
  9. {
  10. var grapes = Console.ReadLine()
  11. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12. .Select(x => Convert.ToInt16(x)).ToArray();
  13.  
  14. var rounds = Convert.ToInt16(Console.ReadLine());
  15.  
  16. var grapesCounter = grapes.Length;
  17.  
  18.  
  19. //---spin for each season until the grapes are less than rounds---
  20. while (grapesCounter >= rounds)
  21. {
  22. //---count the rounds---
  23. for (int counter = 0; counter < rounds; counter++)
  24. {
  25. // -1 => lesser, 0 => normal, 1 => greater
  26. var grapesKind = new int[grapes.Length];
  27. for (int index = 1; index < grapes.Length - 1; index++)
  28. {
  29. if (grapes[index] > grapes[index - 1] && grapes[index] > grapes[index + 1])
  30. {
  31. grapesKind[index] = 1;
  32. grapesKind[index - 1] = -1;
  33. grapesKind[index + 1] = -1;
  34. index++;
  35. }
  36. }
  37. //---calculate the grapes---
  38. for (int index = 0; index < grapes.Length; index++)
  39. {
  40. if (grapesKind[index] == 0 && grapes[index] > 0)
  41. {
  42. grapes[index]++;
  43. }
  44. else if (grapesKind[index] == 1)
  45. {
  46. grapes[index]++;
  47. if (grapes[index - 1] > 0)
  48. {
  49. grapes[index]++;
  50. grapes[index - 1]--;
  51. }
  52. if (grapes[index + 1] > 0)
  53. {
  54. grapes[index]++;
  55. grapes[index + 1]--;
  56. }
  57. index++;
  58. }
  59. }
  60. }
  61. grapesCounter = grapes.Length;
  62. for (int index = 0; index < grapes.Length; index++)
  63. {
  64. if (grapes[index] <= rounds)
  65. {
  66. grapes[index] = 0;
  67. grapesCounter--;
  68. }
  69. }
  70. }
  71. Console.WriteLine(string.Join(" ", grapes.Where(x => x > rounds)));
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment