Advertisement
plamen83

Untitled

Jan 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.96 KB | None | 0 0
  1. namespace _06.Winecraft
  2. {
  3.  
  4.     using System;
  5.     using System.Collections.Generic;
  6.  
  7.     public class Problem06
  8.     {
  9.  
  10.         public static void Main()
  11.         {
  12.             var inputLine = Console.ReadLine();
  13.             var grapeList = InitializeIntList(inputLine);
  14.             var growthDays = int.Parse(Console.ReadLine());
  15.            
  16.  
  17.             while (true)
  18.             {            
  19.                 for (int i = 0; i < growthDays; i++)
  20.                 {
  21.                     var grapesKindArr = new string[grapeList.Count];
  22.                     SetGrapesKinds(grapeList, grapesKindArr);
  23.  
  24.                     for (int j = 0; j < grapeList.Count; j++)
  25.                     {
  26.                         if (grapeList[j] > 0)
  27.                         {
  28.                             ExecuteGrowthRules(grapeList, grapesKindArr, j);
  29.                         }
  30.                     }              
  31.                 }
  32.  
  33.                 SetZeroToGrapesLessOrEqualToGrowthDays(grapeList, growthDays);
  34.  
  35.                 if (!CountOfGrapesBiggerThanGrowthDays(grapeList, growthDays))
  36.                 {
  37.                     break;
  38.                 }
  39.             }
  40.  
  41.             PrintResult(grapeList);
  42.         }
  43.  
  44.         public static List<int> InitializeIntList(string input)
  45.         {
  46.             var inputArr = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  47.             var list = new List<int>();
  48.  
  49.             foreach (var str in inputArr)
  50.             {
  51.                 list.Add(int.Parse(str));
  52.             }
  53.  
  54.             return list;
  55.         }
  56.  
  57.         public static bool CountOfGrapesBiggerThanGrowthDays(List<int> grapeList, int n)
  58.         {
  59.             var cntr = 0;
  60.  
  61.             foreach (var grape in grapeList)
  62.             {
  63.                 if (grape > n)
  64.                 {
  65.                     cntr++;
  66.                 }
  67.             }
  68.  
  69.             return (cntr >= n);
  70.         }
  71.  
  72.         public static void ExecuteGrowthRules(
  73.             List<int> grapeList, string[] grapesKindArr, int i)
  74.         {
  75.             if (grapesKindArr[i] == "normal")
  76.             {
  77.                 grapeList[i]++;
  78.             }
  79.             else if (grapesKindArr[i] == "greater")
  80.             {
  81.                 grapeList[i]++;
  82.                 if (grapeList[i - 1] > 0)
  83.                 {
  84.                     grapeList[i]++;
  85.                     grapeList[i - 1]--;
  86.                 }
  87.  
  88.                 if (grapeList[i + 1] > 0)
  89.                 {
  90.                     grapeList[i]++;
  91.                     grapeList[i + 1]--;
  92.                 }
  93.  
  94.             }
  95.  
  96.         }
  97.  
  98.         public static void SetZeroToGrapesLessOrEqualToGrowthDays(
  99.             List<int> grapeList, int growthDays)
  100.         {
  101.             for (int i = 0; i < grapeList.Count; i++)
  102.             {
  103.                 if (grapeList[i] <= growthDays)
  104.                 {
  105.                     grapeList[i] = 0;
  106.                 }
  107.             }
  108.         }
  109.  
  110.         public static void SetGrapesKinds(List<int> grapeList, string[] grapesKinds)
  111.         {
  112.             SetGreatherGrapes(grapeList, grapesKinds);
  113.  
  114.             if (grapeList.Count > 1)
  115.             {
  116.                 if (grapesKinds[1] == "greater")
  117.                 {
  118.                     grapesKinds[0] = "lesser";
  119.                 }
  120.                 else
  121.                 {
  122.                     grapesKinds[0] = "normal";
  123.                 }
  124.                 if (grapesKinds[grapesKinds.Length - 2] == "greater")
  125.                 {
  126.                     grapesKinds[grapesKinds.Length - 1] = "lesser";
  127.                 }
  128.                 else
  129.                 {
  130.                     grapesKinds[grapesKinds.Length - 1] = "normal";
  131.                 }
  132.             }
  133.  
  134.             for (int i = 1; i < grapeList.Count - 1; i++)
  135.             {
  136.                 if (grapesKinds[i - 1] == "greater" || grapesKinds[i + 1] == "greater")
  137.                 {
  138.                     grapesKinds[i] = "lesser";
  139.                 }
  140.                 else if (grapesKinds[i] == null)
  141.                 {
  142.                     grapesKinds[i] = "normal";
  143.                 }
  144.                
  145.             }
  146.         }
  147.  
  148.         public static void SetGreatherGrapes(List<int> grapeList, string[] grapesKinds)
  149.         {
  150.             for (int i = 1; i < grapesKinds.Length - 1; i++)
  151.             {
  152.                 var curr = grapeList[i];
  153.                 var prev = grapeList[i - 1];
  154.                 var next = grapeList[i + 1];
  155.  
  156.                 if (curr > prev && curr > next)
  157.                 {
  158.                     grapesKinds[i] = "greater";
  159.                 }
  160.             }
  161.         }
  162.  
  163.         public static void PrintResult(List<int> grapesList)
  164.         {
  165.             var result = new List<int>();
  166.  
  167.             foreach (var grapes in grapesList)
  168.             {
  169.                 if (grapes > 0)
  170.                 {
  171.                     result.Add(grapes);
  172.                 }
  173.             }
  174.  
  175.             Console.WriteLine(string.Join(" ", result));
  176.         }
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement