svephoto

The Lift [C#]

Jul 7th, 2021
3,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace TheLift
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int tourists = int.Parse(Console.ReadLine());
  11.  
  12.             int[] lift = Console.ReadLine().Split().Select(int.Parse).ToArray();          
  13.          
  14.             for (int i = 0; i < lift.Length; i++)
  15.             {
  16.                 if (lift[i] < 4)
  17.                 {
  18.                     if (tourists >= 4 - lift[i])
  19.                     {
  20.                         tourists -= 4 - lift[i];
  21.                         lift[i] = 4;
  22.                     }
  23.                     else
  24.                     {
  25.                         lift[i] += tourists;
  26.                         tourists = 0;
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             bool isNotFull = false;
  32.  
  33.             for (int i = 0; i < lift.Length; i++)
  34.             {
  35.                 if (lift[i] < 4)
  36.                 {
  37.                     isNotFull = true;
  38.                     break;
  39.                 }
  40.             }
  41.  
  42.             if (tourists == 0 && isNotFull)
  43.             {
  44.                 Console.WriteLine("The lift has empty spots!");
  45.             }
  46.             else if (tourists > 0 && !isNotFull)
  47.             {
  48.                 Console.WriteLine($"There isn't enough space! {tourists} people in a queue!");
  49.             }
  50.  
  51.             Console.WriteLine(String.Join(" ", lift));
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment