Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _16_Lists_Exe_06Winecraft
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Winecraft
- {
- public static void Main()
- {
- var grapes = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- int growthDays = int.Parse(Console.ReadLine());
- while (grapes.Count > growthDays)
- {
- for (int i = 0; i < growthDays; i++)
- {
- GetGrapesStatePerDay(grapes);
- }
- grapes.RemoveAll(x => x <= growthDays);
- }
- Console.WriteLine(string.Join(" ", grapes));
- }
- private static void GetGrapesStatePerDay(List<int> grapes)
- {
- IncrementEachGrapeByOne(grapes);
- for (int i = 1; i < grapes.Count - 1; i++)
- {
- int currentIndex = i;
- int previousIndex = i - 1;
- int nextIndex = i + 1;
- if (grapes[currentIndex] > grapes[previousIndex] &&
- grapes[currentIndex] > grapes[nextIndex])
- {
- grapes[currentIndex]--;
- if (grapes[previousIndex] > 0)
- {
- grapes[currentIndex]++;
- grapes[previousIndex] -= 2;
- if (grapes[previousIndex] < 0)
- {
- grapes[previousIndex] = 0;
- }
- }
- if (grapes[nextIndex] > 0)
- {
- grapes[currentIndex]++;
- grapes[nextIndex] -= 2;
- if (grapes[nextIndex] < 0)
- {
- grapes[nextIndex] = 0;
- }
- }
- }
- }
- }
- private static void IncrementEachGrapeByOne(List<int> grapes)
- {
- for (int i = 0; i < grapes.Count; i++)
- {
- grapes[i]++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement