Advertisement
Guest User

Untitled

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