simeonP1999 2 Точки

## Programming Fundamentals Mid Exam Retake - 12 August 2020 - "02. The Lift"

Judge ми дава 88/100. Някой ако може да помогне :)

Ето кода: https://pastebin.com/haqgzUzN

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 you will receive the current state of the lift separated by " ".

### 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 on 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 waggons.
Тагове:
0
Axiomatik 2422 Точки

That was a difficult one to find. Basically your validation for the final output messages had to be modified and specifiy whether all people had been transported and any cabin still had some free places or whether all cabins were filled up with people. Without this specification, one of the tests would fail, most probably in the scenario where there were 0 people in the line and the code couldn't differentiate which final message to pick (with full or still empty cabins).

New code(100%)

using System;
using System.Linq;

namespace _2.TheLift
{
class Program
{
static void Main(string[] args)
{
int peopleWaitingForLyft = int.Parse(Console.ReadLine());
int[] wagon = Console.ReadLine().Split().Select(int.Parse).ToArray();
int peopleOnTheCurrentWagon = 0;
int peopleonTheLyft = 0;
bool NoMorePeople = false;

for (int i = 0; i < wagon.Length; i++)
{
while (wagon[i] < 4)
{
wagon[i]++;
peopleOnTheCurrentWagon++;
if (peopleonTheLyft + peopleOnTheCurrentWagon == peopleWaitingForLyft)
{
NoMorePeople = true;
break;
}
}
peopleonTheLyft += peopleOnTheCurrentWagon;
if (NoMorePeople)
{
break;
}
peopleOnTheCurrentWagon = 0;
}

if (peopleWaitingForLyft > peopleonTheLyft)
{
Console.WriteLine(\$"There isn't enough space! {peopleWaitingForLyft - peopleonTheLyft} people in a queue!");
Console.WriteLine(string.Join(" ", wagon));
}
else if (peopleWaitingForLyft < wagon.Length * 4 && wagon.Any(w => w < 4))
{
Console.WriteLine("The lift has empty spots!");
Console.WriteLine(string.Join(" ", wagon));
}
//else if (peopleonTheLyft == peopleWaitingForLyft && NoMorePeople == true)
else if (wagon.All(w => w == 4) && NoMorePeople == true)
{
Console.WriteLine(string.Join(" ", wagon));
}
}
}
}

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