fbinnzhivko

PassionDays 2

Apr 22nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using System;
  2. class PassionDays
  3. {
  4.     static void Main()
  5.     {
  6.         decimal money = decimal.Parse(Console.ReadLine());
  7.         string command = Console.ReadLine();
  8.         int purchases = 0;
  9.  
  10.         while (command != "mall.Enter")
  11.         {
  12.             command = Console.ReadLine();
  13.         }
  14.  
  15.         command = Console.ReadLine();
  16.  
  17.         while (command != "mall.Exit")
  18.         {
  19.             string actions = command;
  20.             for (int i = 0; i < actions.Length; i++)
  21.             {
  22.                 decimal price = 0;
  23.                 if (actions[i] >= 65 && actions[i] <= 90)
  24.                 {
  25.                     price = actions[i] * 0.5m;
  26.                     if (money < price)
  27.                     {
  28.                         continue;
  29.                     }
  30.  
  31.                     money -= price;
  32.                     purchases++;
  33.                 }
  34.                 else if (actions[i] >= 97 && actions[i] <= 122)
  35.                 {
  36.                     price = actions[i] * 0.3m;
  37.                     if (money < price)
  38.                     {
  39.                         continue;
  40.                     }
  41.  
  42.                     money -= price;
  43.                     purchases++;
  44.                 }
  45.                 else if (actions[i] == '%')
  46.                 {
  47.                     if (money > 0)
  48.                     {
  49.                         money /= 2;
  50.                         purchases++;
  51.                     }
  52.                 }
  53.                 else if (actions[i] == '*')
  54.                 {
  55.                     money += 10;
  56.                 }
  57.                 else
  58.                 {
  59.                     price = actions[i];
  60.                     if (money < price)
  61.                     {
  62.                         continue;
  63.                     }
  64.  
  65.                     money -= price;
  66.                     purchases++;
  67.                 }
  68.             }
  69.  
  70.             command = Console.ReadLine();
  71.         }
  72.  
  73.  
  74.         if (purchases == 0)
  75.         {
  76.             Console.WriteLine("No purchases. Money left: {0:f2} lv.", money);
  77.         }
  78.         else
  79.         {
  80.             Console.WriteLine("{0} purchases. Money left: {1:f2} lv.", purchases, money);
  81.         }
  82.  
  83.     }
  84. }
Add Comment
Please, Sign In to add comment