Advertisement
silvana1303

cinema voucher

Apr 29th, 2020
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace exampreparation
  4.  
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int voucher = int.Parse(Console.ReadLine());
  11.             string input = Console.ReadLine();
  12.             int price = 0;
  13.             int movieCounter = 0;
  14.             int foodCounter = 0;
  15.  
  16.             while (input != "End")
  17.             {
  18.                 if (input.Length > 8)
  19.                 {
  20.                     price = input[0] + input[1];
  21.                     if (price <= voucher)
  22.                     {
  23.                         voucher -= price;
  24.                     }
  25.                     else
  26.                     {
  27.                         break;
  28.                     }
  29.                     movieCounter++;
  30.                 }
  31.                 else
  32.                 {
  33.                     price = input[0];
  34.                     if (price <= voucher)
  35.                     {
  36.                         voucher -= price;
  37.                     }
  38.                     else
  39.                     {
  40.                         break;
  41.                     }
  42.                     foodCounter++;
  43.                 }
  44.  
  45.  
  46.                 input = Console.ReadLine();
  47.             }
  48.  
  49.             if (input == "End" || price > voucher)
  50.             {
  51.                 Console.WriteLine($"{movieCounter}");
  52.                 Console.WriteLine($"{foodCounter}");
  53.             }
  54.  
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement