Advertisement
gospod1978

List-Ex/More/Drum Set

Oct 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace fundamental14
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main()
  11.         {
  12.             double saveMoney = double.Parse(Console.ReadLine());
  13.  
  14.             List<int> drums = Console.ReadLine().
  15.                 Split().
  16.                 Select(int.Parse).
  17.                 ToList();
  18.  
  19.             List<int> powerRed = new List<int>(drums);
  20.  
  21.             string input;
  22.  
  23.             input = DrumsResult(ref saveMoney, drums, powerRed);
  24.  
  25.             Console.WriteLine(string.Join(" ", powerRed));
  26.             Console.WriteLine("Gabsy has {0:f2}lv.", saveMoney);
  27.  
  28.         }
  29.  
  30.         private static string DrumsResult(ref double saveMoney, List<int> drums, List<int> powerRed)
  31.         {
  32.             string input;
  33.             while ((input = Console.ReadLine()) != "Hit it again, Gabsy!")
  34.             {
  35.                 int power = int.Parse(input);
  36.                 for (int i = 0; i < drums.Count; i++)
  37.                 {
  38.                     powerRed[i] -= power;
  39.  
  40.                     if (powerRed[i] <= 0)
  41.                     {
  42.                         int replaseDrum = drums[i] * 3;
  43.  
  44.                         if (replaseDrum >= saveMoney)
  45.                         {
  46.                             drums.RemoveAt(i);
  47.                             powerRed.RemoveAt(i);
  48.                             i--;
  49.                         }
  50.                         else
  51.                         {
  52.                             powerRed[i] = drums[i];
  53.                             saveMoney -= replaseDrum;
  54.                         }
  55.                     }
  56.                 }
  57.  
  58.             }
  59.  
  60.             return input;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement