Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _0_5DrumSet
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             double budget = double.Parse(Console.ReadLine());
  12.  
  13.             List<int> drums = Console.ReadLine()
  14.                 .Split(' ')
  15.                 .Select(int.Parse)
  16.                 .ToList();
  17.  
  18.             List<int> price = new List<int>();
  19.             price.AddRange(drums);
  20.  
  21.             string command = string.Empty;
  22.  
  23.             while (true)
  24.             {
  25.                 command = Console.ReadLine();
  26.                 if (command == "Hit it again, Gabsy!") break;
  27.                 int hit = int.Parse(command);
  28.                 for (int i = 0; i < drums.Count; i++)
  29.                 {
  30.                     drums[i] -= hit;
  31.                     if (drums[i] <= 0)
  32.                     {
  33.                         if (budget - (price[i] * 3) >= 0)
  34.                         {
  35.                             budget = budget - (price[i] * 3);
  36.                             drums[i] = price[i];
  37.                         }
  38.                         else
  39.                         {
  40.                             drums.RemoveAt(i);
  41.                             price.RemoveAt(i);
  42.                             i++;
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.             foreach (var drum in drums)
  48.             {
  49.                 Console.Write(drum + " ");
  50.             }
  51.             Console.WriteLine();
  52.             Console.WriteLine($"Gabsy has {budget:f2}lv.");
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement