Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. //using System.Collections.Generic;
  5. //using System.Text;
  6. //using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication14
  9. {
  10.     class Program
  11.     {
  12.  
  13.         static int[] grapes;
  14.         /// <summary>
  15.         /// ---За да следя по-добре методите ги поразместих малко иначе всичко си е твое---
  16.         /// </summary>
  17.         /// <param name="args"></param>
  18.         static void Main(string[] args)
  19.         {
  20.             grapes = Console.ReadLine().Split().Select(int.Parse).ToArray();
  21.             int n = int.Parse(Console.ReadLine());
  22.             do
  23.             {
  24.                 for (int cnt = 0; cnt < n; cnt++)
  25.                 {
  26.                     BloomGrapes();
  27.                 }
  28.                 KillGrapesWithPowerLesserThan(n);
  29.             } while (StrongGrapesAreGreaterOrEqualThan(n));
  30.             PrintLiveGrapes(n);
  31.         }
  32.  
  33.  
  34.         // ---Hier is OK---
  35.         static bool StrongGrapesAreGreaterOrEqualThan(int threshold)
  36.         {
  37.             int strongGrapesCnt = 0;
  38.             for (int cnt = 0; cnt < grapes.Length; cnt++)
  39.             {
  40.                 if (grapes[cnt] > threshold)
  41.                 {
  42.                     strongGrapesCnt++;
  43.                 }
  44.             }
  45.             return (strongGrapesCnt >= threshold);/* ---за да е изпълнено условиетоброяча трябва да е и
  46.             равен на дните*/
  47.         }
  48.  
  49.         static void BloomGrapes()
  50.         {
  51.             for (int index = 0; index < grapes.Length; index++)
  52.             {
  53.                 //---Why if is alive from the index  => continue?---
  54.                 //---Maybe hire  must be not alive---
  55.                 if (!IsAlive(index) || IsLesserGrape(index))/*---ако грозда е равен на нула или слаб
  56.                     продължаваш а пресмятанията за слабите го правиш в проверката за
  57.                     големите гроздове---*/
  58.                 {
  59.                     continue;
  60.                 }
  61.                 else if (IsGreaterGrape(index))
  62.                 {
  63.                     grapes[index]++;
  64.                     if (grapes[index - 1] > 0)
  65.                     {
  66.                         grapes[index - 1]--;
  67.                         grapes[index]++;
  68.                     }
  69.                     if (grapes[index + 1] > 0)
  70.                     {
  71.                         grapes[index + 1]--;
  72.                         grapes[index]++;
  73.                     }
  74.                 }
  75.                 //else if (IsLesserGrape(index))
  76.                 //{
  77.                 //    continue;//grapes[index]--;
  78.                 //}
  79.                 else
  80.                 {
  81.                     grapes[index]++;
  82.                 }
  83.             }
  84.         }
  85.  
  86.         //---Hier is OK---
  87.         static bool IsAlive(int index)
  88.         {
  89.             if (index < 0 || index > grapes.Length -1 || grapes[index] <= 0)// <=
  90.             {
  91.                 return false;
  92.             }
  93.             return grapes[index] > 0;
  94.         }
  95.  
  96.         //---Hier is OK---
  97.         static bool IsGreaterGrape(int index)
  98.         {
  99.             if (index <= 0 || index >= grapes.Length - 1)
  100.             {
  101.                 return false;
  102.             }
  103.             return (grapes[index] > grapes[index - 1] && grapes[index] > grapes[index + 1]);
  104.         }
  105.  
  106.         //---Why if left index and(&&) rigth index must be greater---
  107.         //---Is not enough when left or(||) rigth index are greater?---
  108.         static bool IsLesserGrape(int index)
  109.         {
  110.             return IsGreaterGrape(index - 1) /*&&*/|| IsGreaterGrape(index + 1);
  111.         }
  112.        
  113.         static void KillGrapesWithPowerLesserThan(int threshfold)
  114.         {
  115.             for (int cnt = 0; cnt < grapes.Length; cnt++)
  116.             {
  117.                 if (grapes[cnt] <= threshfold)
  118.                 {
  119.                     grapes[cnt] = 0;
  120.                 }
  121.             }
  122.         }
  123.        
  124.         //---Hier must not be alive, then must be greater then N
  125.         static void PrintLiveGrapes(int n)
  126.         {
  127.             //Console.WriteLine(string.Join(" ", grapes.Where(x => x > n)));
  128.             for (int index = 0; index < grapes.Length; index++)
  129.             {
  130.                 if (/*IsAlive(index)*/grapes[index] > n)
  131.                 {
  132.                     Console.Write(grapes[index] + " ");
  133.                 }
  134.             }
  135.             //Console.WriteLine();
  136.         }
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement