Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2.  
  3. class Practice
  4. {
  5.     static void Main()
  6.     {
  7.         decimal money = decimal.Parse(Console.ReadLine());
  8.         string input = Console.ReadLine();
  9.  
  10.         //wait for "mall.Enter" input
  11.         while (input!="mall.Enter")
  12.         {
  13.             input = Console.ReadLine();
  14.         }
  15.         input = Console.ReadLine();
  16.         decimal price = 0;
  17.         decimal currentItem = 0; int orders = 0;
  18.  
  19.         //wait for "mall.Exit" input
  20.         while (input!="mall.Exit")
  21.         {
  22.             for (int i = 0; i < input.Length; i++)
  23.             {
  24.                 currentItem = input[i];
  25.                 if (input[i]>='A'&&input[i]<='Z')
  26.                 {
  27.                     price = currentItem * 0.5m;
  28.                 }
  29.                 else if (input[i]>='a'&&input[i]<='z')
  30.                 {
  31.                     price = currentItem * 0.3m;
  32.                 }
  33.                 else if (input[i]=='%')
  34.                 {
  35.                     if (money > 0)
  36.                     {
  37.                         money /= 2; orders++;
  38.                     }
  39.                 }
  40.                 else if (input[i]=='*')
  41.                 {
  42.                     money += 10;
  43.                 }
  44.                 else { price = currentItem; }
  45.  
  46.                 if (price!=0&&(money-price)>=0) { money -= price; orders++; }
  47.  
  48.                 price = 0; currentItem = 0;
  49.             }
  50.             input = Console.ReadLine();
  51.         }
  52.  
  53.         if (orders == 0)
  54.         {
  55.             Console.WriteLine("No purchases. Money left: {0:F2} lv.", money);
  56.         }
  57.         else
  58.         {
  59.             Console.WriteLine("{0} purchases. Money left: {1:F2} lv.", orders, money);
  60.         }
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement