Library Fine


Problem Statement :


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 = 15 Hackos * (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, the 
fine = 500 Hackos * (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 10000 Hackos.

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


Example
d1, m1, y1 = 14, 7, 2018
d2, m2, y2 = 5, 7, 2018

The first values are the return date and the second are the due date. The years are the same and the months are the same. The book is 14 - 5 = 9 days late. Return 9 * 5 = 135.


Function Description

Complete the libraryFine function in the editor below.

libraryFine has the following parameter(s):

d1, m1, y1: returned date day, month and year, each an integer
d2, m2, y2: due date day, month and year, each an integer

Returns
int: the amount of the fine or 0 if there is none


Input Format

The first line contains 3 space-separated integers, d1, m1, y1, denoting the respective day, month  and year on which the book was returned.
The second line contains 3 space-separated integers, d2, m2, y2, denoting the respective day, month  and year on which the book was due to be returned.

Constraints
1 <= d1, d2 <= 31
1 <= m1, m2 <=12
1 <= y1, y2 <= 3000
It is guaranteed that the dates will be valid Gregorian calender dates.



Solution :



title-img


                            Solution in C :

C  :

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {    
    
    int edd, emm, eyyyy, add, amm, ayyyy;
    int fine =0;
    
    scanf("%d%d%d%d%d%d", &add, &amm, &ayyyy, &edd, &emm, &eyyyy);
    
    if(ayyyy < eyyyy){
        fine = 0;    
    }
    else if(ayyyy > eyyyy){
        fine = 10000;
    }
    else if(ayyyy == eyyyy){
        if(amm < emm){
            fine = 0;
        }
        else if(amm > emm){
            fine = 500 * (amm - emm);
        }
        else if(amm == emm){
            if(add <= edd){
                fine = 0;
            }
            else if(add > edd){
                fine = 15 * (add - edd);
            }
        }
    }
    
    printf("%d", fine);
    
    return 0;
}












C ++  :

#include<iostream>
using namespace std;
int main()
{
    int actual[3],expected[3],i,j;
    for(i=0;i<3;i++)
    cin>>actual[i];
    for(i=0;i<3;i++)
    cin>>expected[i];
   
    if(actual[2]-expected[2]<0)
        cout<<0;
    else if(actual[2]-expected[2]>0)
        cout<<10000;
    else if(actual[1]-expected[1]<0)
        cout<<0;
    else if(actual[1]-expected[1]>0)
        cout<<500*(actual[1]-expected[1]);
    else if(actual[0]-expected[0]>0)
        cout<<15*(actual[0]-expected[0]);
    else
        cout<<0;

}   










Java  :


import java.util.Scanner;

class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d2 = sc.nextInt(), m2 = sc.nextInt(), y2 = sc.nextInt();
        int d1 = sc.nextInt(), m1 = sc.nextInt(), y1 = sc.nextInt();
        if (y2 > y1) {
            System.out.println(10000);
        } else if (y2 < y1 || m2 < m1 || m2 == m1 && d2 <= d1) {
            System.out.println(0);
        } else if (m1 == m2) {
            System.out.println(15 * (d2 - d1));
        } else {
            System.out.println(500 * (m2 - m1));
        }
    }
}










python 3  :

"""libraryfine.py"""

def main(N):
	sum0 = 0
	D = N[0][0]-N[1][0]
	M = N[0][1]-N[1][1]
	Y = N[0][2]-N[1][2]

	if D > 0 and M == 0 and Y == 0:
		sum0 = 15*(D)
	elif M > 0 and Y == 0:
		sum0 = 500*(M)
	elif Y > 0:
		sum0 = 10000*(Y)

	print(sum0)


if __name__ == '__main__':
	N = [list(map(int,input().split(" "))) for i in [1,2]]
	main(N)
                        








View More Similar Problems

Balanced Brackets

A bracket is considered to be any one of the following characters: (, ), {, }, [, or ]. Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and (). A matching pair of brackets is not balanced if the set of bra

View Solution →

Equal Stacks

ou have three stacks of cylinders where each cylinder has the same diameter, but they may vary in height. You can change the height of a stack by removing and discarding its topmost cylinder any number of times. Find the maximum possible height of the stacks such that all of the stacks are exactly the same height. This means you must remove zero or more cylinders from the top of zero or more of

View Solution →

Game of Two Stacks

Alexa has two stacks of non-negative integers, stack A = [a0, a1, . . . , an-1 ] and stack B = [b0, b1, . . . , b m-1] where index 0 denotes the top of the stack. Alexa challenges Nick to play the following game: In each move, Nick can remove one integer from the top of either stack A or stack B. Nick keeps a running sum of the integers he removes from the two stacks. Nick is disqualified f

View Solution →

Largest Rectangle

Skyline Real Estate Developers is planning to demolish a number of old, unoccupied buildings and construct a shopping mall in their place. Your task is to find the largest solid area in which the mall can be constructed. There are a number of buildings in a certain two-dimensional landscape. Each building has a height, given by . If you join adjacent buildings, they will form a solid rectangle

View Solution →

Simple Text Editor

In this challenge, you must implement a simple text editor. Initially, your editor contains an empty string, S. You must perform Q operations of the following 4 types: 1. append(W) - Append W string to the end of S. 2 . delete( k ) - Delete the last k characters of S. 3 .print( k ) - Print the kth character of S. 4 . undo( ) - Undo the last (not previously undone) operation of type 1 or 2,

View Solution →

Poisonous Plants

There are a number of plants in a garden. Each of the plants has been treated with some amount of pesticide. After each day, if any plant has more pesticide than the plant on its left, being weaker than the left one, it dies. You are given the initial values of the pesticide in each of the plants. Determine the number of days after which no plant dies, i.e. the time after which there is no plan

View Solution →