Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. namespace _16_Lists_Exe_06Winecraft
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Winecraft
  8.     {
  9.         public static void Main()
  10.         {
  11.             var grapes = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.             int growthDays = int.Parse(Console.ReadLine());
  13.  
  14.             while (grapes.Count > growthDays)
  15.             {
  16.                 for (int i = 0; i < growthDays; i++)
  17.                 {
  18.                     GetGrapesStatePerDay(grapes);
  19.                 }
  20.                 grapes.RemoveAll(x => x <= growthDays);
  21.             }
  22.             Console.WriteLine(string.Join(" ", grapes));
  23.         }
  24.  
  25.         private static void GetGrapesStatePerDay(List<int> grapes)
  26.         {
  27.             IncrementEachGrapeByOne(grapes);
  28.  
  29.             for (int i = 1; i < grapes.Count - 1; i++)
  30.             {
  31.                 int currentIndex = i;
  32.                 int previousIndex = i - 1;
  33.                 int nextIndex = i + 1;
  34.  
  35.                 if (grapes[currentIndex] > grapes[previousIndex] &&
  36.                 grapes[currentIndex] > grapes[nextIndex])
  37.                 {
  38.                     grapes[currentIndex]--;
  39.                     if (grapes[previousIndex] > 0)
  40.                     {
  41.                         grapes[currentIndex]++;
  42.                         grapes[previousIndex] -= 2;
  43.                         if (grapes[previousIndex] < 0)
  44.                         {
  45.                             grapes[previousIndex] = 0;
  46.                         }
  47.                     }
  48.                     if (grapes[nextIndex] > 0)
  49.                     {
  50.                         grapes[currentIndex]++;
  51.                         grapes[nextIndex] -= 2;
  52.                         if (grapes[nextIndex] < 0)
  53.                         {
  54.                             grapes[nextIndex] = 0;
  55.                         }
  56.                     }
  57.                 }
  58.                
  59.             }
  60.  
  61.         }
  62.  
  63.         private static void IncrementEachGrapeByOne(List<int> grapes)
  64.         {
  65.             for (int i = 0; i < grapes.Count; i++)
  66.             {
  67.                 grapes[i]++;
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement