Mario_Ankona

Winecraft

Jun 29th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace winecraft
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> grapes = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  14.             List<int> greaterGrapeIndex = new List<int> { };
  15.             int growth = int.Parse(Console.ReadLine());
  16.             while (grapes.Count(i => i != 0) >= growth)
  17.             {
  18.                 Process(grapes, greaterGrapeIndex, growth);
  19.             }
  20.             Cleanup(grapes, growth);
  21.             Console.WriteLine(string.Join(" ", grapes));
  22.  
  23.  
  24.         }
  25.         static void Process(List<int> grapes, List<int> greaterGrapeIndex, int growth)
  26.         {
  27.             int counter = 0;
  28.             while (counter < growth)
  29.             {
  30.  
  31.  
  32.                 for (int i = 0; i < grapes.Count; i++)
  33.                 {
  34.                     if (i == 0)
  35.                     {
  36.                         greaterGrapeIndex.Add(1);
  37.                     }
  38.  
  39.                     else if (i > 0 && i < grapes.Count - 1)
  40.                     {
  41.                         if (grapes[i - 1] < grapes[i] && grapes[i] > grapes[i + 1])
  42.                         {
  43.                             greaterGrapeIndex.Add(2);
  44.                         }
  45.                         else
  46.                         {
  47.                             greaterGrapeIndex.Add(1);
  48.                         }
  49.  
  50.                     }
  51.  
  52.                     else if (i == grapes.Count - 1)
  53.                     {
  54.                         greaterGrapeIndex.Add(1);
  55.                     }
  56.  
  57.                 }
  58.                 for (int j = 0; j < greaterGrapeIndex.Count; j++)
  59.                 {
  60.                     if (greaterGrapeIndex[j] == 2)
  61.                     {
  62.                         greaterGrapeIndex[j - 1] = 0;
  63.                         greaterGrapeIndex[j + 1] = 0;
  64.                     }
  65.                 }
  66.  
  67.                 for (int k = 0; k < grapes.Count; k++)
  68.                 {
  69.                     if (greaterGrapeIndex[k] == 1)
  70.                     {
  71.                         grapes[k] += 1;
  72.                     }
  73.                     else if (greaterGrapeIndex[k] == 2)
  74.                     {
  75.                         grapes[k] += 1;
  76.  
  77.                         if (grapes[k - 1] > 0 && grapes[k + 1] > 0)
  78.                         {
  79.                             grapes[k] += 2;
  80.                             grapes[k - 1] -= 1;
  81.                             grapes[k + 1] -= 1;
  82.                         }
  83.                         else if (grapes[k - 1] > 0 && grapes[k + 1] <= 0)
  84.                         {
  85.                             grapes[k] += 1;
  86.                             grapes[k - 1] -= 1;
  87.                         }
  88.                         else if (grapes[k - 1] <= 0 && grapes[k + 1] > 0)
  89.                         {
  90.                             grapes[k] += 1;
  91.                             grapes[k + 1] -= 1;
  92.                         }
  93.  
  94.                     }
  95.                 }
  96.                 greaterGrapeIndex.Clear();
  97.  
  98.                 counter++;
  99.             }
  100.             for (int l = 0; l < grapes.Count; l++)
  101.             {
  102.                 if (grapes[l] <= growth)
  103.                 {
  104.                     grapes[l] = 0;
  105.                 }
  106.             }
  107.  
  108.         }
  109.  
  110.         static void Cleanup(List<int> grapes, int growth)
  111.         {
  112.  
  113.             for (int m = 0; m < grapes.Count; m++)
  114.             {
  115.                 if (grapes[m] == 0)
  116.                 {
  117.                     grapes.RemoveAt(m);
  118.                     --m;
  119.                 }
  120.             }
  121.         }
  122.     }
  123.  
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment