Teo_Yanchev

C# Fundamentals - 02. TheLift - MidExam 12.08.2020

Oct 23rd, 2020 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._TheLift
  5. {
  6. class TheLift
  7. {
  8. static void Main(string[] args)
  9. {
  10. int people = int.Parse(Console.ReadLine());
  11. int[] liftSpots = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToArray();
  15.  
  16. bool isEmpty = false;
  17. int drive = people;
  18.  
  19. for (int i = 0; i < liftSpots.Length; i++)
  20. {
  21. if (liftSpots[i] == 4)
  22. {
  23. continue;
  24. }
  25.  
  26. if (people == 0)
  27. {
  28. if (liftSpots[i] < 4)
  29. {
  30. isEmpty = true;
  31. }
  32. break;
  33. }
  34.  
  35. for (int j = 0; j < 4; j++)
  36. {
  37. if (liftSpots[i] == 4 || people == 0)
  38. {
  39. break;
  40. }
  41.  
  42. people -= 1;
  43. liftSpots[i] += 1;
  44. }
  45.  
  46. if (liftSpots[i] < 4)
  47. {
  48. isEmpty = true;
  49. }
  50. }
  51.  
  52. if (isEmpty)
  53. {
  54. Console.WriteLine("The lift has empty spots!");
  55. Console.WriteLine(string.Join(' ', liftSpots));
  56. }
  57.  
  58. else if (people > 0)
  59. {
  60. Console.WriteLine($"There isn't enough space! {people} people in a queue!");
  61. Console.WriteLine(string.Join(' ', liftSpots));
  62. }
  63.  
  64. else
  65. {
  66. Console.WriteLine(string.Join(' ', liftSpots));
  67. }
  68. }
  69. }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment