Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- //using System.Collections.Generic;
- //using System.Text;
- //using System.Threading.Tasks;
- namespace ConsoleApplication14
- {
- class Program
- {
- static int[] grapes;
- /// <summary>
- /// ---За да следя по-добре методите ги поразместих малко иначе всичко си е твое---
- /// </summary>
- /// <param name="args"></param>
- static void Main(string[] args)
- {
- grapes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int n = int.Parse(Console.ReadLine());
- do
- {
- for (int cnt = 0; cnt < n; cnt++)
- {
- BloomGrapes();
- }
- KillGrapesWithPowerLesserThan(n);
- } while (StrongGrapesAreGreaterOrEqualThan(n));
- PrintLiveGrapes(n);
- }
- // ---Hier is OK---
- static bool StrongGrapesAreGreaterOrEqualThan(int threshold)
- {
- int strongGrapesCnt = 0;
- for (int cnt = 0; cnt < grapes.Length; cnt++)
- {
- if (grapes[cnt] > threshold)
- {
- strongGrapesCnt++;
- }
- }
- return (strongGrapesCnt >= threshold);/* ---за да е изпълнено условиетоброяча трябва да е и
- равен на дните*/
- }
- static void BloomGrapes()
- {
- for (int index = 0; index < grapes.Length; index++)
- {
- //---Why if is alive from the index => continue?---
- //---Maybe hire must be not alive---
- if (!IsAlive(index) || IsLesserGrape(index))/*---ако грозда е равен на нула или слаб
- продължаваш а пресмятанията за слабите го правиш в проверката за
- големите гроздове---*/
- {
- continue;
- }
- else if (IsGreaterGrape(index))
- {
- grapes[index]++;
- if (grapes[index - 1] > 0)
- {
- grapes[index - 1]--;
- grapes[index]++;
- }
- if (grapes[index + 1] > 0)
- {
- grapes[index + 1]--;
- grapes[index]++;
- }
- }
- //else if (IsLesserGrape(index))
- //{
- // continue;//grapes[index]--;
- //}
- else
- {
- grapes[index]++;
- }
- }
- }
- //---Hier is OK---
- static bool IsAlive(int index)
- {
- if (index < 0 || index > grapes.Length -1 || grapes[index] <= 0)// <=
- {
- return false;
- }
- return grapes[index] > 0;
- }
- //---Hier is OK---
- static bool IsGreaterGrape(int index)
- {
- if (index <= 0 || index >= grapes.Length - 1)
- {
- return false;
- }
- return (grapes[index] > grapes[index - 1] && grapes[index] > grapes[index + 1]);
- }
- //---Why if left index and(&&) rigth index must be greater---
- //---Is not enough when left or(||) rigth index are greater?---
- static bool IsLesserGrape(int index)
- {
- return IsGreaterGrape(index - 1) /*&&*/|| IsGreaterGrape(index + 1);
- }
- static void KillGrapesWithPowerLesserThan(int threshfold)
- {
- for (int cnt = 0; cnt < grapes.Length; cnt++)
- {
- if (grapes[cnt] <= threshfold)
- {
- grapes[cnt] = 0;
- }
- }
- }
- //---Hier must not be alive, then must be greater then N
- static void PrintLiveGrapes(int n)
- {
- //Console.WriteLine(string.Join(" ", grapes.Where(x => x > n)));
- for (int index = 0; index < grapes.Length; index++)
- {
- if (/*IsAlive(index)*/grapes[index] > n)
- {
- Console.Write(grapes[index] + " ");
- }
- }
- //Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement