Advertisement
Dimitar46

The Lift

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