krum_43 683 Точки

## Проблем при една изпитна задача от изпита от 12.08.2020 г-Mid Exam Retake-The Lift

Условието на задачата може да се види от линка :

https://judge.softuni.bg/Contests/Practice/Index/2517#1

С моето решение стигам до 77/100(тест1 и тест5 не минават)

Ето и линк към кода :

https://pastebin.com/hpxuGW3t

Тагове:
0
Axiomatik 1626 Точки
``````using System;
using System.Linq;

namespace Program
{
class Program
{
static void Main(string[] args)
{

.Split()
.Select(int.Parse)
.ToArray();

int maxCapacity = 4;

bool noMorePeople = false;

for (int i = 0; i < currentState.Length; i++)
{
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));
}
}
}
}``````

``````using System;
using System.Linq;

namespace _2.TheLift
{
class Program
{
static void Main(string[] args)
{
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 (wagon.All(w => w == 4) && NoMorePeople == true)
{
Console.WriteLine(string.Join(" ", wagon));
}
}
}
}``````

1
krum_43 683 Точки

Thanks for the solutions. Both solutions are good.

Best,

1