By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: National Court - PHP Exam Task

+2 votes

Every day thousands of people pass by the reception at "National Court" with various questions to ask and the employees have to help everyone by providing correct information and to answer all questions.

  • There are 3 employees working on the reception all day long.
  • Each of them can handle different number of people per hour.

Your task is to calculate how much time it will take to answer all the questions of a given number of people.

  • First you will receive 3 lines with integers, representing the count of people that each of the employee can help per hour.
  • On the next line you will receive the total people count as a single integer.

Every fourth hour all the employees have a one-hour break before they start working again.

Calculate the time needed to answer all people's questions and print it in the following format:

"Time needed: {time}h."

Input / Constraints:

  • On first three lines -  each employee`s efficiency -  an integer in the range [1 - 100]
  • On the fourth line - people count – an integer in the range [0 – 10000]
  • Input will always be valid and in the range specified


  • Print a single line: "Time needed: {time}h."
  • Allowed working time / memory: 100ms / 16MB


national court php exam task

asked in PHP category by user mitko

1 Answer

+2 votes

Here is my answer:


$peoplePerHour = 0;
$timeNeeded = 0;

for ($i = 0; $i < 3; $i++) {
    $input = intval(readline());
    $peoplePerHour += $input;
$people = readline();

$timeNeeded += $people / $peoplePerHour;

$timeNeeded = ceil($timeNeeded);

$count = 0;
for ($i = 1; $i < $timeNeeded / 3; $i++) {

$all = $count + $timeNeeded;
echo "Time needed: " . $all . "h.";
answered by user andrew