Advertisement
Valantina

CinemaVoucher/ЕX

Jun 14th, 2019
94
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. namespace CinemaVoucher
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int voucherValue = int.Parse(Console.ReadLine());
  10.             int moviePrice = 0;
  11.             int productPrice = 0;
  12.             int purchasedProducts = 0;
  13.             int purchasedTickets = 0;
  14.  
  15.             while (voucherValue >= 0)
  16.             {
  17.                 string purchase = Console.ReadLine();
  18.                 if (purchase == "End")
  19.                 {
  20.                     Console.WriteLine($"{purchasedTickets}");
  21.                     Console.WriteLine($"{purchasedProducts}");
  22.                     break;
  23.                 }
  24.                 if (purchase.Length > 8)
  25.                 {
  26.                     moviePrice = purchase[0] + purchase[1];
  27.                     if (moviePrice > voucherValue)
  28.                     {
  29.                         Console.WriteLine($"{purchasedTickets}");
  30.                         Console.WriteLine($"{purchasedProducts}");
  31.                         break;
  32.                     }
  33.                     voucherValue -= moviePrice;
  34.                     purchasedTickets++;
  35.                    
  36.                 }
  37.                 else if (purchase.Length <= 8)
  38.                 {
  39.                     productPrice = purchase[0];
  40.                     if (productPrice > voucherValue)
  41.                     {
  42.                         Console.WriteLine($"{purchasedTickets}");
  43.                         Console.WriteLine($"{purchasedProducts}");
  44.                         break;
  45.                     }
  46.                     voucherValue -= productPrice;
  47.                     purchasedProducts++;
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement