Advertisement
Radostta

Passion Days

Sep 11th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace PassionDays
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             decimal money = decimal.Parse(Console.ReadLine());
  14.             string input = Console.ReadLine(); //read <enter.Mall> here
  15.  
  16.             int purchasesCount = 0;
  17.             decimal price = 0;
  18.  
  19.             //Following not needed => there is no input before <mall.Enter> in the tests:
  20.             //while (input != "mall.Enter")
  21.             //{
  22.             //    input = Console.ReadLine(); // or continue;
  23.             //}
  24.  
  25.             input = Console.ReadLine(); //read first action input here
  26.  
  27.             while (input != "mall.Exit")
  28.             {
  29.               for (int i = 0; i < input.Length; i++)
  30.                 {
  31.                     if (input[i] >= 65 && input[i] <= 90)
  32.                     {
  33.                         price = input[i] * 0.5m;
  34.  
  35.                         if (money >= price)
  36.                         {
  37.                             money -= price;
  38.                             purchasesCount++;
  39.                         }
  40.                         //if (money < price) continue;
  41.                         //money -= price;
  42.                         //purchasesCount++;
  43.                     }
  44.                     else if (input[i] >= 97 && input[i] <= 122)
  45.                     {
  46.                         price = input[i] * 0.3m;
  47.                         if (money >= price)
  48.                         {
  49.                             money -= price;
  50.                             purchasesCount++;
  51.                         }
  52.                         //if (money < price) continue;
  53.                         //money -= price;
  54.                         //purchasesCount++;
  55.                     }
  56.                     else if (input[i] == 37)
  57.                     {
  58.                         if (money > 0)
  59.                         {
  60.                             money /= 2;
  61.                             purchasesCount++;
  62.                         }
  63.                     }
  64.                     else if (input[i] == 42)
  65.                     {
  66.                         money += 10;
  67.                     }
  68.                     else
  69.                     {
  70.                         price = input[i];
  71.                         if (money >= price)
  72.                         {
  73.                             money -= price;
  74.                             purchasesCount++;
  75.                         }
  76.                         //if (money < price) continue;
  77.                         //money -= price;
  78.                         //purchasesCount++;
  79.                     }
  80.                 }
  81.                 input = Console.ReadLine(); //read all other action inputs or <mall.Exit> here
  82.             }
  83.  
  84.             if (purchasesCount == 0)
  85.             {
  86.                 Console.WriteLine($"No purchases. Money left: {money:f2} lv.");
  87.             }
  88.             else
  89.             {
  90.                 Console.WriteLine($"{purchasesCount} purchases. Money left: {money:f2} lv.");
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement