Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace winecraft
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> grapes = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- List<int> greaterGrapeIndex = new List<int> { };
- int growth = int.Parse(Console.ReadLine());
- while (grapes.Count(i => i != 0) >= growth)
- {
- Process(grapes, greaterGrapeIndex, growth);
- }
- Cleanup(grapes, growth);
- Console.WriteLine(string.Join(" ", grapes));
- }
- static void Process(List<int> grapes, List<int> greaterGrapeIndex, int growth)
- {
- int counter = 0;
- while (counter < growth)
- {
- for (int i = 0; i < grapes.Count; i++)
- {
- if (i == 0)
- {
- greaterGrapeIndex.Add(1);
- }
- else if (i > 0 && i < grapes.Count - 1)
- {
- if (grapes[i - 1] < grapes[i] && grapes[i] > grapes[i + 1])
- {
- greaterGrapeIndex.Add(2);
- }
- else
- {
- greaterGrapeIndex.Add(1);
- }
- }
- else if (i == grapes.Count - 1)
- {
- greaterGrapeIndex.Add(1);
- }
- }
- for (int j = 0; j < greaterGrapeIndex.Count; j++)
- {
- if (greaterGrapeIndex[j] == 2)
- {
- greaterGrapeIndex[j - 1] = 0;
- greaterGrapeIndex[j + 1] = 0;
- }
- }
- for (int k = 0; k < grapes.Count; k++)
- {
- if (greaterGrapeIndex[k] == 1)
- {
- grapes[k] += 1;
- }
- else if (greaterGrapeIndex[k] == 2)
- {
- grapes[k] += 1;
- if (grapes[k - 1] > 0 && grapes[k + 1] > 0)
- {
- grapes[k] += 2;
- grapes[k - 1] -= 1;
- grapes[k + 1] -= 1;
- }
- else if (grapes[k - 1] > 0 && grapes[k + 1] <= 0)
- {
- grapes[k] += 1;
- grapes[k - 1] -= 1;
- }
- else if (grapes[k - 1] <= 0 && grapes[k + 1] > 0)
- {
- grapes[k] += 1;
- grapes[k + 1] -= 1;
- }
- }
- }
- greaterGrapeIndex.Clear();
- counter++;
- }
- for (int l = 0; l < grapes.Count; l++)
- {
- if (grapes[l] <= growth)
- {
- grapes[l] = 0;
- }
- }
- }
- static void Cleanup(List<int> grapes, int growth)
- {
- for (int m = 0; m < grapes.Count; m++)
- {
- if (grapes[m] == 0)
- {
- grapes.RemoveAt(m);
- --m;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment