Advertisement
Guest User

Winecraft

a guest
Jun 25th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.65 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.             //---spin for each season until the grapes are less than rounds---
  19.             while (grapesCounter >= rounds)
  20.             {
  21.                 //---count the rounds---
  22.                 for (int counter = 0; counter < rounds; counter++)
  23.                 {
  24.                     // -1 => lesser, 0 => normal, 1 => greater
  25.                     var grapesKind = new int[grapes.Length];
  26.                     for (int index = 1; index < grapes.Length - 1; index++)
  27.                     {
  28.                         if (grapes[index] > grapes[index - 1] && grapes[index] > grapes[index + 1])
  29.                         {
  30.                             grapesKind[index] = 1;
  31.                             grapesKind[index - 1] = -1;
  32.                             grapesKind[index + 1] = -1;
  33.                             index++;
  34.                         }
  35.                     }
  36.                     //---calculate the grapes---
  37.                     for (int index = 0; index < grapes.Length; index++)
  38.                     {
  39.                         if (grapesKind[index] == 0)
  40.                         {
  41.                             grapes[index]++;
  42.                         }
  43.                         else if (grapesKind[index] == 1)
  44.                         {
  45.                             grapes[index]++;
  46.                             if (grapes[index - 1] > 0)
  47.                             {
  48.                                 grapes[index]++;
  49.                                 grapes[index - 1]--;
  50.                             }
  51.                             if (grapes[index + 1] > 0)
  52.                             {
  53.                                 grapes[index]++;
  54.                                 grapes[index + 1]--;
  55.                             }
  56.                             index++;
  57.                         }
  58.                     }
  59.                 }
  60.                 for (int index = 0; index < grapes.Length; index++)
  61.                 {
  62.                     if (grapes[index] <= rounds)
  63.                     {
  64.                         grapes[index] = 0;
  65.                         grapesCounter--;
  66.                     }
  67.                 }
  68.             }
  69.             Console.WriteLine(string.Join(" ", grapes.Where(x => x > rounds)));
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement