KEMBAR78
PD Loop | PDF | Mathematics
0% found this document useful (0 votes)
7 views6 pages

PD Loop

The document outlines five programming problems related to sequences and calculations in a hospital and logistics context. Problem 1 involves generating a sequence of numbers with multiples of 4 amplified, Problem 2 focuses on calculating triangular numbers, Problem 3 deals with counting treated and untreated patients, Problem 4 calculates percentages of numbers divisible by 2, 3, and 4, and Problem 5 involves calculating transportation costs based on cargo weight. Each problem includes input data, expected output, and test cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

PD Loop

The document outlines five programming problems related to sequences and calculations in a hospital and logistics context. Problem 1 involves generating a sequence of numbers with multiples of 4 amplified, Problem 2 focuses on calculating triangular numbers, Problem 3 deals with counting treated and untreated patients, Problem 4 calculates percentages of numbers divisible by 2, 3, and 4, and Problem 5 involves calculating transportation costs based on cargo weight. Each problem includes input data, expected output, and test cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of Computer Science

University of Engineering and Technology, Lahore

________________________________________________________________________

Problem 1:
In this challenge, you must generate a sequence of consecutive numbers, from a lower bound
that will always be equal to 1, up to a variable given higher bound (including the bounds in the
sequence).

Each number of the sequence that can be exactly divided by 4 must be amplified by 10 (see
notes below).

Given a higher bound num, implement a code that displays the sequence of numbers with
every multiple of 4 has been amplified on the console.
Notes:
● The given parameter num will always be equal to or greater than 1.
● Remember to include the num as the higher bound of the sequence
● A number a amplified by a factor b can also be read as: a * b.
● A number a is exactly divisible by a number b when the remainder of the division a / b is
equal to 0.

Tests Cases

● amplify(4) ➞ 1, 2, 3, 40
// Create a sequence from 1 to 4
// 4 is exactly divisible by 4, so it will be 4*10 = 40

● amplify(3) ➞ 1, 2, 3
// Create a sequence from 1 to 3
// There are no numbers that can be exactly divided by 4

● amplify(25) ➞ 1, 2, 3, 40, 5, 6, 7, 80, 9, 10, 11, 120, 13, 14, 15, 160, 17, 18, 19, 200, 21,
22, 23, 240, 25
// Create a sequence from 1 to 25
// The numbers exactly divisible by 4 are: 4 (4*10 = 40), 8 (8 * 10 = 80)... and so on.
Problem 2:
This Triangular Number Sequence is generated from a pattern of dots that form a triangle. The
first 5 numbers of the sequence, or dots, are:

1, 3, 6, 10, 15, 21 …

This means that the first triangle has just one dot, the second one has three dots, the third one
has 6 dots and so on as shown in figure.
Write a code that prints the number of dots when given its corresponding triangle number of
the sequence.

Test Cases:
● triangle(1) ➞ 1
● triangle(6) ➞ 21
● triangle(215) ➞ 23220

Problem 3:
For a certain period of time, patients arrive at the hospital every day for an examination. It
initially has 7 doctors. Each doctor can treat only one patient per day, but sometimes there is a
shortage of doctors, so the remaining patients are sent to other hospitals. Every third day the
hospital makes calculations and if the count of untreated patients is greater than the count of
treated ones, another doctor is appointed. Appointment takes place before the daily patient
acceptance begins.

Write a program that calculates for a given period of time, the count of treated and untreated
patients.

Input Data
Input is read from the console and contains:

● On the first line – the period, for which you need to make calculations. Integer in the
range of [1 … 1000].
● On the next lines (equal to the count of days) – count of the patients, who arrive for
treatment for the current day. Integer in the range of [0 … 10 000].

Output Data

Print on the console 2 lines:

● On the first line: “Treated patients: {count of treated patients}.”


● On the second line: “Untreated patients: {count of untreated patients}.”

Test Cases:

Input Output Explanation

4 Treated patients: 23. Day 1: 7 treated and 0 untreated patients for the day
7 Untreated patients: 21.
27 Day 2: 7 treated and 20 untreated patients for the day
9
1 Day 3: By this moment the treated patients are 14,

and untreated ones – 20 –> New doctor is appointed.

–> 8 treated and 1 untreated patients for the day

Day 4: 1 treated and 0 untreated patients for the day

Total: 23 treated and 21 untreated patients.

6 Treated patients: 40.


25 Untreated patients: 87.
25
25
25
25
2

3 Treated patients: 21.


7 Untreated patients: 0.
7
7
Problem 4:

We have n integers in the range of [1 ... 1000]. Among them, some percentage p1 are divisible
without remainder by 2, percentage p2 are divisible without remainder by 3, percentage p3 are
divisible without remainder by 4. Write a program that calculates and prints the p1, p2 and p3
percentages.

Example: We have n = 10 numbers: 680, 2, 600, 200, 800, 799, 199, 46, 128, 65. We get the
following distribution and visualization:

Division without Numbers Count Percent


remainder by:

2 680, 2, 600, 200, 800, 7 p1 = (7 / 10) * 100 =


46, 128 70.00%

3 600 1 p2 = (1 / 10) * 100 =


10.00%

4 680, 600, 200, 800, 5 p3 = (5 / 10) * 100 =


128 50.00%

Input Data:

On the first line of the input is the integer n (1 ≤ n ≤ 1000) – count of numbers. On each of the
next n lines we have one integer in the range of [1 … 1000] – numbers that needs to be
checked for division.

Output Data:

Print on the console 3 lines, each of them containing a percentage between 0% and 100% for
example 25.00%, 66.67%, 57.14%.

● On the first line – percentage of the numbers that are divisible by 2.


● On the second line – percentage of the numbers that are divisible by 3.
● On the third line – percentage of the numbers that are divisible by 4.

Test Cases:

Input Output

10 70.00%
680 10.00%
2 50.00%
600
200
800
799
199
46
128
65

3 33.33%
3 100.00%
6 0.00%
9

1 100.00%
12 100.00%
100.00%

Problem 5:

You are responsible for the logistics of various types of cargo. Depending on the weight of each
cargo, you need a different vehicle, and this will cost a different price per ton:

● Up to 3 tons – a minibus (200 USD per ton).


● From over 3 and up to 11 tons – truck (175 USD per ton).
● Over 11 tons – train (120 USD per ton).

Your task is to calculate the average price per ton of the cargo, and also what percentage of the
cargo is transported in each vehicle.

Input Data:

From the console we must read a sequence of numbers, each on a separate line:

● First line: count of cargo for transportation – integer in the range of [1 … 1000].
● On the next lines we pass the tonnage of the current cargo – integer in the range of [1
… 1000].

Output Data:

Print on the console 4 lines, as follows:


● Line #1 – the average price per ton of the cargo (rounded up to the second digit after
the decimal point).
● Line #2 – percentage of the cargo, carried by minibus (between 0.00% and 100.00%,
rounded up to the second digit after the decimal point).
● Line #3 – percentage of the cargo, carried by truck (between 0.00% and 100.00%).
● Line #4 – percentage of the cargo, carried by train (between 0.00% and 100.00%).

Test Cases:

Input Output Explanation

4 143.80 By minibus you transport two of the cargo 1 + 3, total of 4 tons.


1 16.00% By truck you transport one of the cargo: 5 tons.
5 20.00% By train you transport one of the cargo: 16 tons.
16 64.00% Sum of all cargo is: 1 + 5 + 16 + 3 = 25 tons.
3 Percentage of the cargo by minibus: 4/25*100 = 16.00%
Percentage of the cargo by truck: 5/25*100 = 20.00%
Percentage of the cargo by train: 16/25*100 = 64.00%
Average price per ton of carried cargo: (4 * 200 + 5 * 175 + 16 *
120) / 25 = 143.80

5 149.38
2 7.50%
10 42.50%
20 50.00%
1
7

4 120.35
53 0.00%
7 0.63%
56 99.37%
999

You might also like