Advertisement
Guest User

10. Profit

a guest
Aug 25th, 2020
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _10._Profit
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Solution #1
  10.             int oneLevCoins = int.Parse(Console.ReadLine());
  11.             int twoLevCoins = int.Parse(Console.ReadLine());
  12.             int fiveLevCoins = int.Parse(Console.ReadLine());
  13.             int sum = int.Parse(Console.ReadLine());
  14.             int currentSum = 0;
  15.  
  16.             for (int one = 0; one <= oneLevCoins * 1; one++)
  17.             {
  18.                 for (int two = 0; two <= twoLevCoins * 2; two += 2)
  19.                 {
  20.                     for (int five = 0; five <= fiveLevCoins * 5; five += 5)
  21.                     {
  22.                         currentSum = one + two + five;
  23.                         if (currentSum == sum)
  24.                         {
  25.                             int onesCount = one / 1;
  26.                             int twosCount = two / 2;
  27.                             int fivesCount = five / 5;
  28.  
  29.                             Console.WriteLine($"{onesCount} * 1 lv. + {twosCount} * 2 lv. + {fivesCount} * 5 lv. = {currentSum} lv.");
  30.                         }
  31.                     }
  32.                 }
  33.             }
  34.  
  35.             //Solution #2
  36.             int oneLevCoins = int.Parse(Console.ReadLine());
  37.             int twoLevCoins = int.Parse(Console.ReadLine());
  38.             int fiveLevCoins = int.Parse(Console.ReadLine());
  39.             int sum = int.Parse(Console.ReadLine());
  40.  
  41.             for (int one = 0; one <= oneLevCoins; one++)
  42.             {
  43.                 for (int two = 0; two <= twoLevCoins; two++)
  44.                 {
  45.                     for (int five = 0; five <= fiveLevCoins; five++)
  46.                     {
  47.                         if (one * 1 + two * 2 + five * 5 == sum)
  48.                         {
  49.                             Console.WriteLine($"{one} * 1 lv. + {two} * 2 lv. + {five} * 5 lv. = {sum} lv.");
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
  57.  
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement