 # https://www.codechef.com/MACE2021/problems/MCODE02

Author: Setter’s name

Tester: Tester’s name

Editorialist: [Editorialist’s name]

DIFFICULTY : EASY

If - else

# PROBLEM:

Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any).

The fee structure is as follows:

1. If the book is returned on or before the expected return date, no fine will be charged (i.e. fine = 0).

2. If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, fine = Rs 15 * (the number of days late).

3. If the book is returned after the expected return month but still within the same calendar year as the expected return date, fine = Rs 500 * (the number of months late).

4. If the book is returned after the calendar year in which it was expected, there is a fixed fine of Rs 10,000.

Charges are based only on the least precise measure of lateness. For example, whether a book is due January 1, 2017or December 31, 2017, if it is returned January 1, 2018, that is a year late and the fine would be Rs 10,000.

#QUICK EXPLANATION:

The solution is to calculate the library fine if the book is not returned within the expected return date. The fine is calculated by comparing the day, month and year of actual return date with that of expected return date.

#EXPLANATION:

To calculate the fine, we must first compare the expected year and the returned year, then the expected month to the returned month, and finally the expected day to the returned day. The fine should be initialized to 0.

Years:

• If return year < expected year, then the book was returned early and fine = 0.
• If return year > expected year, then fine = Rs 10,000.
• If return year = expected year, then the book was either returned on time or was returned less than a year late; to determine this, we move on to our Months logic.

Months:

• If return month < expected month, then the book was returned early and fine = 0.
• If return month > expected month, then the book was returned some number of months late and fine = (return month - expected month) * Rs 500.
• If return month = expected month, then the book was either returned on time or less than a month late; to determine this, we move on to our Days logic.

Days:

• If return day <= expected day, then fine = 0 .
• If return day > expected day, then fine = (return day - expected day) * Rs 15.

# SOLUTIONS:

(python 3)

Setter's Solution

def libraryFine(d1,m1,y1,d2,m2,y2):

if y1>y2:

#if year of return is greater than year due

return 10000

elif m1>m2 and y1==y2:

#if returned in the same year and month of return is greater than month due

return (m1-m2)*500

elif d1>d2 and y1==y2 and m1==m2:

#if returned in the same year and month, and the date of return is greater than due date

return (d1-d2)*15

else:

return 0

d1,m1,y1 = map(int,input().split())

d2,m2,y2 = map(int,input().split())

print(libraryFine(d1,m1,y1,d2,m2,y2))

Tester's Solution

Same Person

Editorialist's Solution

Same Person