Advertisement
ad2bg

PassionDays

Dec 18th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. namespace PassionDays
  2. {
  3.     using System;
  4.  
  5.     class PassionDays
  6.     {
  7.         static void Main()
  8.         {
  9.             decimal money = decimal.Parse(Console.ReadLine());
  10.  
  11.             int countPurchases = 0;
  12.             string command = string.Empty;
  13.  
  14.             // skip any commands before "mall.Enter"
  15.             do { command = Console.ReadLine(); } while (command != "mall.Enter");
  16.  
  17.             // process commands until "mall.Exit"
  18.             while (true)
  19.             {
  20.                 command = Console.ReadLine();
  21.                 if (command == "mall.Exit") break;
  22.  
  23.                 foreach (char action in command)
  24.                 {
  25.                     if (action == '*') { money += 10; continue; }
  26.  
  27.                     decimal price = 0;
  28.                     if (char.IsLetter(action) && char.IsUpper(action)) { price = 0.5m * (int)action; }
  29.                     else if (char.IsLetter(action) && char.IsLower(action)) { price = 0.3m * (int)action; }
  30.                     else if (action == '%') { price = money / 2; }
  31.                     else { price = (int)action; }
  32.  
  33.                     if (money < price || money == 0) continue;
  34.  
  35.                     money -= price;
  36.                     countPurchases++;
  37.                 }
  38.             }
  39.  
  40.             // display results
  41.             string purchases = countPurchases == 0 ? "No" : countPurchases.ToString();
  42.             Console.WriteLine($"{purchases} purchases. Money left: {money:f2} lv.");
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement