Advertisement
Guest User

winekraft

a guest
Jun 29th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.38 KB | None | 0 0
  1. namespace _06.Winecraft
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Winecraft
  8.     {
  9.         static void Main()
  10.         {
  11.  
  12.             int[] grapes = Console.ReadLine()
  13.                 .Split(new char[] { ' ' },
  14.                 StringSplitOptions.RemoveEmptyEntries)
  15.                 .Select(int.Parse)
  16.                 .ToArray();
  17.  
  18.             int n = int.Parse(Console.ReadLine());
  19.  
  20.             int grapesCounter = 0;
  21.  
  22.  
  23.             do
  24.             {
  25.                 //Grouwing days
  26.                 for (int i = 0; i < n; i++)
  27.                 {
  28.                     GrapesLvlChange(grapes);
  29.                 }
  30.  
  31.                 KillGrapesLowerOrEqualTo(n, grapes);
  32.  
  33.                 grapesCounter = grapes
  34.                     .Where(g => g > n)
  35.                     .ToArray()
  36.                     .Length;
  37.  
  38.             }
  39.             while (grapesCounter >= n);
  40.  
  41.             grapes = grapes
  42.                 .Where(g => g > n)
  43.                 .ToArray();
  44.  
  45.             Console.WriteLine(string.Join(" ", grapes));
  46.  
  47.         }
  48.  
  49.  
  50.         //Add or remove a lvl from grapes deppend of the grape Type
  51.         static void GrapesLvlChange(int[] grapes)
  52.         {
  53.             HashSet<int> lesserGrapesIndexes = new HashSet<int>();
  54.  
  55.             for (int i = 0; i < grapes.Length; i++)
  56.             {
  57.  
  58.                 //int first = grapes[i - 1];
  59.                 //int greatGrape = grapes[i];
  60.                 //int last = grapes[i + 1];
  61.  
  62.                 bool isGreater = GreateGrape(i, grapes);
  63.  
  64.  
  65.                 if (isGreater)
  66.                 {
  67.                     lesserGrapesIndexes.Add(i - 1);
  68.                     lesserGrapesIndexes.Add(i + 1);
  69.                 }
  70.             }
  71.             StealGrapeFromLesserGrapes(grapes);
  72.  
  73.             LvlUpGrapesDifferendThenLessarGrape(grapes, lesserGrapesIndexes);
  74.  
  75.         }
  76.  
  77.         //Steal 1 lvl from lesser grapes
  78.         private static void StealGrapeFromLesserGrapes(int[] grapes)
  79.         {
  80.             for (int i = 0; i < grapes.Length; i++)
  81.             {
  82.                 //int first = grapes[i - 1];
  83.                 //int greater = grapes[i];
  84.                 //int last = grapes[i + 1];
  85.  
  86.                 bool isGreater = GreateGrape(i, grapes);
  87.  
  88.                 //int lvlUpGreaterGrape = 0;
  89.  
  90.                 if (isGreater)
  91.                 {
  92.                     int first = grapes[i - 1];
  93.                     int greater = grapes[i];
  94.                     int last = grapes[i + 1];
  95.                     //if (first > 0 && last <= 0)
  96.                     //{
  97.                     //    grapes[i - 1]--;
  98.                     //    lvlUpGreaterGrape++;
  99.                     //}
  100.                     //if (first <= 0 && last > 0)
  101.                     //{
  102.                     //    grapes[i + 1]--;
  103.                     //    lvlUpGreaterGrape++;
  104.                     //}
  105.                     //if (first > 0 && last > 0)
  106.                     //{
  107.                     //    grapes[i - 1]--;
  108.                     //    grapes[i + 1]--;
  109.                     //    lvlUpGreaterGrape += 2;
  110.                     //}
  111.  
  112.                     //grapes[i] += lvlUpGreaterGrape;
  113.                     //
  114.  
  115.                     // ---тук намаля слабите и присвоява стоиностите им на големите
  116.                     if (first > 0)
  117.                     {
  118.                         grapes[i - 1]--;
  119.                         grapes[i]++;
  120.                     }
  121.                     if (last > 0)
  122.                     {
  123.                         grapes[i + 1]--;
  124.                         grapes[i]++;
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.  
  130.         //Add 1 lvl to the grapes who are differend then lesser
  131.         static void LvlUpGrapesDifferendThenLessarGrape(int[] grapes,
  132.             HashSet<int> lesserGrapesIndexes)
  133.         {
  134.             for (int i = 0; i < grapes.Length; i++)
  135.             {
  136.                 //foreach (var index in lesserGrapesIndexes)
  137.                 //{
  138.                 //    if (index == i)
  139.                 //    {
  140.                 //        i++;
  141.                 //    }
  142.                 //}
  143.  
  144.                 // ---увеличаваш всички които не са слаби!---
  145.                 if (grapes[i] > 0 && !lesserGrapesIndexes.Contains(i))
  146.                 {
  147.                     grapes[i]++;
  148.                 }
  149.             }
  150.         }
  151.  
  152.         //Check for Greater Grapes
  153.         static bool GreateGrape(int index, int[] grapes)
  154.         {
  155.             // ---метода проверява дали грозда от индекса може да е по-голям---
  156.             // ---и след това дали наистина е по-голям
  157.             // ---така циклите могат да си обикалят по целия масив
  158.             if (index > 0 && index < grapes.Length - 1)
  159.             {
  160.                 return grapes[index - 1] < grapes[index] && grapes[index + 1] < grapes[index];
  161.             }
  162.             return false;
  163.  
  164.         }
  165.  
  166.         //Set lower then N grapes to 0
  167.         static void KillGrapesLowerOrEqualTo(int n, int[] grapes)
  168.         {
  169.  
  170.             for (int i = 0; i < grapes.Length; i++)
  171.             {
  172.                 if (grapes[i] < n)
  173.                 {
  174.                     grapes[i] = 0;
  175.                 }
  176.             }
  177.         }
  178.     }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement