UTS Programming Competition 2016 Problem 2

From ProgSoc Wiki

Jump to: navigation, search

This is a part of the UTS Programming Competition 2016 Problem Set.

Problem 2: Libra Solidus Denarius

Run time limit: 2 seconds

Problem Description

The year is 1961, and you are a cashier at Umbert Threapleton & Sons' department store in the city.

As a reward for customers who buy products in bulk, management have decreed that a discount be applied to each bulk purchase. The exact discount as a percentage varies from product to product.

All prices in the store are stated in pounds, shillings and pence. A pound is subdivided into 20 shillings and each shilling in turn is subdivided into 12 pence. Not exactly the most convenient of currencies to add together nor apply discounts to.

Umbert Threapleton, a forward-thinking man who likes to embrace modern technologies, has installed a UNIVAC computer in the storage area of the department store for the purpose of computing complex calculations. All employees, including cashiers, have access to the computer. It is on this computer that you will run your program to calculate the discounted price for the customer.

Data Specification


A single test case on a single line, with five integers separated by a space.

The first three numbers represent the unit price of a product in pounds (0 ≤ L ≤ 1000), shillings (0 ≤ S ≤ 19) and pence (0 ≤ P ≤ 11), respectively.

The fourth number is the quantity of units (0 ≤ Q ≤ 1000) to be purchased.

The fifth number is the discount (1 ≤ D ≤ 99) to be applied as a percentage.


Three lines with three integers separated by a space, representing a calculated price in pounds, shillings and pence, respectively. Round fractions of pence to the nearest integer value (e.g rounding 0.5 yields 1).

The first line is the total price prior to the discount being applied.

The second line is the total price after the discount is applied.

The third line is the unit price after the discount is applied.

Sample Input

3 16 8 150 7

Sample Output

575 0 0
534 15 0
3 11 4


Put your solutions here!

John's C# solution

John has a solution in C#.

You can run the unit tests like this:

svn co https://www.progclub.org/svn/pcrepo/jj5-test/trunk/progcomp-2016/q2/ jj5-progcomp-2016-q2
bash jj5-progcomp-2016-q2/test.sh

Should print zero on the last line to indicate all the tests ran successfully.

You can calculate the solution itself like this:

svn co https://www.progclub.org/svn/pcrepo/jj5-test/trunk/progcomp-2016/q2/ jj5-progcomp-2016-q2
bash jj5-progcomp-2016-q2/run.sh 2>/dev/null

Tom's Java solution

import java.io.*;
import java.util.*;

class LSD
	static void calc_lsd(double d)
		double pounds = d / 240.0;
		double shillings = (pounds - Math.floor(pounds)) * 20.0;
		double pence = (shillings - Math.floor(shillings)) * 12.0;
		System.out.println(Math.round(Math.floor(pounds)) + " " + Math.round(Math.floor(shillings)) + " " + Math.round(pence));
	public static void main(String args[])
		Scanner in = new Scanner(System.in);
                int l = in.nextInt();
                int s = in.nextInt();
                int p = in.nextInt();
                int q = in.nextInt();
                int d = in.nextInt();

	 	double pennies = (l * 240) + (s * 12) + p;
		double bulk = q * pennies;
		double discount = (1 - (d/100.0));

		calc_lsd(discount * bulk);
		calc_lsd(discount * pennies);
Personal tools