Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 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 PassionDays
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var money = decimal.Parse(Console.ReadLine());
  14.             string input;
  15.             char inputChar;
  16.             var purchases = 0;
  17.             bool exit = false;
  18.  
  19.             while (exit == false)
  20.             {
  21.                 var start = Console.ReadLine();
  22.                 if (start == "mall.Enter")
  23.                 {
  24.                     while (true)
  25.                     {
  26.                         input = Console.ReadLine();
  27.  
  28.                         if (input == "mall.Exit")
  29.                         {
  30.                             exit = true;
  31.                             break;
  32.                         }
  33.                         else
  34.                         {
  35.                             //loop the string
  36.                             for (int i = 0; i < input.Length; i++)
  37.                             {
  38.                                 inputChar = input[i];
  39.                                 //add mone no purchase
  40.                                 if (inputChar == '*')
  41.                                 {
  42.                                     money += 10;
  43.                                 }
  44.                                 //halves the money
  45.                                 else if (inputChar == '%' && money > 0)
  46.                                 {
  47.                                     money /= 2.0M;
  48.                                     purchases++;
  49.                                 }
  50.                                 //char is letter
  51.                                 else if (char.IsLetter(inputChar))
  52.                                 {
  53.                                     if (char.IsUpper(inputChar) && (int)(inputChar) * 0.5M <= money)
  54.                                     {
  55.                                         purchases++;
  56.                                         money -= (int)(inputChar) * 0.5M;
  57.                                     }
  58.                                     else if (char.IsLower(inputChar) && (int)(inputChar) * 0.3M <= money)
  59.                                     {
  60.                                         purchases++;
  61.                                         money -= (int)(inputChar) * 0.3M;
  62.                                     }
  63.                                 }
  64.                                 else
  65.                                 {
  66.                                     if ((int)(inputChar) <= money)
  67.                                     {
  68.                                         money -= (int)(inputChar);
  69.                                         purchases++;
  70.                                     }
  71.  
  72.                                 }
  73.                             }
  74.                         }
  75.                     }
  76.                 }
  77.             }
  78.  
  79.             if (purchases > 0)
  80.             {
  81.                 Console.WriteLine($"{purchases} purchases. Money left: {money:F2} lv.");
  82.             }
  83.             else
  84.             {
  85.                 Console.WriteLine($"No purchases. Money left: {money:f2} lv.");
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement