PhoenixMaster123 2 Точки

## 02. The Lift

Write a program that finds a place for the tourist on a lift.

Every wagon should have a maximum of 4 people on it. If a wagon is full, you should direct the people to the next one with space available.

### Input

• On the first line, you will receive how many people are waiting to get on the lift
• On the second line, you will receive the current state of the lift separated by a single space: " ".

### Output

When there is no more available space left on the lift, or there are no more people in the queue, you should print on the console the final state of the lift's wagons separated by " " and one of the following messages:

• If there are no more people and the lift have empty spots, you should print:

"The lift has empty spots!

{wagons separated by ' '}"

• If there are still people in the queue and no more available space, you should print:

"There isn't enough space! {people} people in a queue!

{wagons separated by ' '}"

• If the lift is full and there are no more people in the queue, you should print only the wagons separated by " "

### Examples

 Input Output 15 0 0 0 0 The lift has empty spots! 4 4 4 3 Comment First state - 4 0 0 0 -> 11 people left Second state – 4 4 0 0 -> 7 people left Third state – 4 4 4 0 -> 3 people left Input Output 20 0 2 0 There isn't enough space! 10 people in a queue! 4 4 4 Comment First state - 4 2 0  -> 16 people left Second state – 4 4 0  -> 14 people left Third state – 4 4 4 -> 10 people left, but there're no more wagons.

Това е задачата изкарвам 70/100, но вместо с Array правя задачата с List

using System;
using System.Collections.Generic;
using System.Linq;

namespace _02._The_Lift
{
internal class Program
{
static void Main(string[] args)
{
// int[] seats = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int wagons = 4;
int result = peopleWaiting;
int normal = 0;
for (int i = 0; i < seats.Count; i++)
{

if(seats[i] != 0)
{
peopleWaiting+=Math.Abs(seats[i]);
}
seats[i] = wagons;
peopleWaiting -= 4;

if(peopleWaiting < 0)
{
seats.RemoveAt(seats.Count-1);
result -= normal * wagons;
peopleWaiting = 0;
}
if(peopleWaiting == 0)
{
Console.WriteLine("The lift has empty spots!");
Console.WriteLine(string.Join(" ", seats));
break;
}
normal++;

}
if(peopleWaiting > 0)
{
Console.WriteLine(\$"There isn't enough space! {peopleWaiting} people in a queue!");
Console.WriteLine(string.Join(" ", seats));
}

}
}
}

Тагове:
0
18/02/2022 22:50:06
Axiomatik 1993 Точки
``````using System;
using System.Collections.Generic;
using System.Linq;

namespace _02._The_Lift
{
internal class Program
{
static void Main(string[] args)
{
// int[] seats = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int fullCapacity = 4;
int result = peopleWaiting;
//int normal = 0;
for (int i = 0; i < seats.Count; i++)
{
// Standard Solution
//int emptySeats = fullCapacity - seats[i];

//if (emptySeats > 0)
//{
//    if (peopleWaiting < emptySeats)
//    {
//        seats[i] += peopleWaiting;
//        peopleWaiting -= emptySeats;
//    }
//    else
//    {
//        peopleWaiting -= emptySeats;
//        seats[i] += emptySeats;
//    }
//}
//else
//{
//    continue;
//}

// Super Compact Variant
int emptySeats = Math.Min(peopleWaiting, fullCapacity - seats[i]);
seats[i] += emptySeats;
peopleWaiting -= emptySeats;

if (peopleWaiting <= 0)
{
break;
}
}

// If there are no more people and the lift have empty spots, you should print:
if (peopleWaiting <= 0 && seats.Any(s => s < fullCapacity))
{
Console.WriteLine(\$"The lift has empty spots!");
//Console.WriteLine(string.Join(" ", seats));
}
// If there are still people in the queue and no more available space, you should print:
else if (peopleWaiting > 0 && seats.All(s => s == 4))
{
Console.WriteLine(\$"There isn't enough space! {peopleWaiting} people in a queue!");
//Console.WriteLine(string.Join(" ", seats));
}

// If the lift is full and there are no more people in the queue, you should print only the wagons separated by " "
Console.WriteLine(string.Join(" ", seats));
}
}
}
``````

Good discussion on this exercise => https://softuni.bg/forum/37716/python-programming-fundamentals-mid-exam-retake-12-august-2020-problem-2-the-lift

;-)

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.