Advertisement
Dimitar46

The lift

Jun 20th, 2022
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2.TheLift
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int people = int.Parse(Console.ReadLine());
  12.             int copyPeople = people;
  13.             List<int> currentState = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.             int seats = currentState.Sum();
  15.             int maxSeats = currentState.Count() * 4;
  16.             for (int i = 0; i < currentState.Count; i++)
  17.             {
  18.                 int value = currentState[i];
  19.                 int addedPeople = 4 - value;
  20.                 if (addedPeople <= people)
  21.                 {
  22.                     currentState[i] += addedPeople;
  23.                     people -= addedPeople;
  24.                 }
  25.                 else
  26.                 {
  27.                     currentState[i] += people;
  28.                     people = 0;
  29.                 }
  30.             }
  31.  
  32.             if (people == 0 && copyPeople == maxSeats - seats)
  33.             {
  34.                 Console.WriteLine(string.Join(" ",currentState));
  35.             }
  36.             else if (people == 0 && maxSeats - seats> currentState.Sum())
  37.             {
  38.                 Console.WriteLine("The lift has empty spots!");
  39.                 Console.WriteLine(string.Join(" ", currentState));
  40.             }
  41.             else if (people > 0 && maxSeats == currentState.Sum())
  42.             {
  43.                 Console.WriteLine($"There isn't enough space! {people} people in a queue!");
  44.                 Console.WriteLine(string.Join(" ", currentState));
  45.             }
  46.  
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement