Advertisement
VZhelev

Problem 04

Jun 4th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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 SoftUni
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             float money = float.Parse(Console.ReadLine());
  14.             string input = "";
  15.             int purchases = 0;
  16.             float x = 0.0f;
  17.            
  18.             do
  19.             {
  20.                 input = Console.ReadLine();
  21.             }while(input != "mall.Enter");
  22.            
  23.             input = Console.ReadLine();
  24.            
  25.             while(input != "mall.Exit")
  26.             {
  27.                 for(byte i = 0; i < input.Length; i++)
  28.                 {
  29.                     if(input[i] == '%')
  30.                     {
  31.                         if(money > 0)
  32.                         {
  33.                             money /= 2;
  34.                             purchases++;
  35.                         }
  36.                            
  37.                     }else if(input[i] == '*')
  38.                     {
  39.                         money += 10;
  40.                     }else if(input[i] >= 65 && input[i] <= 90)
  41.                     {
  42.                         // uppercase letter
  43.                         x = input[i] / 2.0f;
  44.                         if(money >= x)
  45.                         {
  46.                             money -= x;
  47.                             purchases++;
  48.                         }
  49.                            
  50.                        
  51.                     }else if(input[i] >= 97 && input[i] <= 122)
  52.                     {
  53.                         // lowercase letter
  54.                         x = input[i] * 0.3f;
  55.                         if(money >= x)
  56.                         {
  57.                             money -= x;
  58.                             purchases++;
  59.                         }
  60.                            
  61.                     }else if(money >= input[i])
  62.                     {
  63.                         money -= input[i];
  64.                         purchases++;
  65.                     }
  66.                        
  67.                 }
  68.                 // read next line
  69.                 input = Console.ReadLine();
  70.             }
  71.             if(purchases > 0)
  72.                 Console.WriteLine("{0} purchases. Money left: {1:F2} lv.", purchases, money);
  73.             else
  74.                 Console.WriteLine("No purchases. Money left: {0:F2} lv.", money);
  75.            
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement