madeofglass

Untitled

Mar 6th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _01.PassionDays
  4. {
  5.     class PassionDays
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             decimal money = decimal.Parse(Console.ReadLine());
  10.  
  11.             int countPurchases = 0;
  12.             string command = "";
  13.  
  14.             do {command = Console.ReadLine(); } while (command != "mall.Enter");
  15.  
  16.             while (true)
  17.             {
  18.                 command = Console.ReadLine();
  19.                 if (command == "mall.Exit")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 foreach (char action in command)
  25.                 {
  26.                     if (action == '*')
  27.                     {
  28.                         money += 10;
  29.                         continue;
  30.                     }
  31.                                        
  32.                     decimal price = 0;
  33.  
  34.                     if (char.IsLetter(action) && char.IsUpper(action))
  35.                     {
  36.                         price = 0.5m * (int)action;
  37.                     }
  38.                     else if (char.IsLetter(action) && char.IsLower(action))
  39.                     {
  40.                         price = 0.3m * (int)action;
  41.                     }
  42.                     else if (action == '%')
  43.                     {
  44.                         price = money / 2;
  45.                     }
  46.                     else
  47.                     {
  48.                         price = (int)action;
  49.                     }
  50.  
  51.                     if (money < price || money == 0)
  52.                     {
  53.                         continue;
  54.                     }
  55.  
  56.                     money -= price;
  57.                     countPurchases++;
  58.                 }
  59.             }
  60.  
  61.             string purchases = countPurchases == 0 ? "No" : countPurchases.ToString();
  62.  
  63.             Console.WriteLine($"{purchases} purchases. Money left: {money:f2} lv.");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment