Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

PetarNeshkov5360 avatar PetarNeshkov5360 23 Точки

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

Здравейте! Задачата ми дава в judge 44/100, но не ми показва къде греша. Ще се радвам, ако някой намери грешката ми. 

Благодаря предварително!

https://pastebin.com/dHSgcu4f

Линк към judge:https://judge.softuni.bg/Contests/Practice/Index/2517#1

Условие:

Problem 2. 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 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.

 

 

Input JS

Output

[

 "15",

 "0 0 0 0 0"

]

The lift has empty spaces!

4 4 4 3 0

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 JS

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
Programming Basics with C#
Axiomatik avatar Axiomatik 2422 Точки
Best Answer

Made some changes to your code, hope this helps.

New code (100%):

using System;
using System.Linq;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            int waitingPeople = int.Parse(Console.ReadLine());

            int[] currentState = Console.ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();

            //int nondifference = 0;

            int maxCapacity = 4;

            bool noMorePeople = false;

            for (int i = 0; i < currentState.Length; i++)
            {
                //if (currentState[i] >= 4)
                //{
                //    currentState[i] = 4;
                //    waitingPeople -= currentState[i];

                //}
                //else if (currentState[i] == 0 || currentState[i] < 0)
                //{
                //    int PreviousLeft;
                //    PreviousLeft = waitingPeople;
                //    if (PreviousLeft - 4 < 0)
                //    {
                //        currentState[i] = PreviousLeft;
                //    }
                //    else currentState[i] = 4;
                //    waitingPeople -= currentState[i];

                //}
                //else if (currentState[i] < 4)
                //{
                //    waitingPeople -= currentState[i];
                //    currentState[i] = 4;
                //}

                int currentWagon = currentState[i];

                if (waitingPeople - (maxCapacity - currentWagon) == 0)
                {
                    waitingPeople -= maxCapacity - currentWagon;
                    currentState[i] = 4;
                    noMorePeople = true;
                    break;
                }
                else if (waitingPeople - (maxCapacity - currentWagon) < 0)
                {
                    currentState[i] = waitingPeople;
                    waitingPeople = 0;
                    noMorePeople = true;
                    break;
                }
                else
                {
                    waitingPeople -= maxCapacity - currentWagon;
                    currentState[i] = 4;
                }
            }

            bool emptyCabins = false;

            for (int i = 0; i < currentState.Length; i++)
            {
                if (currentState[i] < 4)
                {
                    emptyCabins = true;
                    break;
                }
            }

            if (noMorePeople == true && emptyCabins == true)
            {
                Console.WriteLine("The lift has empty spots!");
                Console.WriteLine(String.Join(" ", currentState));

            }
            else if (waitingPeople > 0 && emptyCabins == false)
            {
                Console.WriteLine($"There isn't enough space! {waitingPeople} people in a queue!");
                Console.WriteLine(String.Join(" ", currentState));
            }
            else if (waitingPeople == 0 && emptyCabins == false)
            {
                Console.WriteLine(String.Join(" ", currentState));
            }
        }
    }
}

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