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

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 →

AND xor OR

Given an array of distinct elements. Let and be the smallest and the next smallest element in the interval where . . where , are the bitwise operators , and respectively. Your task is to find the maximum possible value of . Input Format First line contains integer N. Second line contains N integers, representing elements of the array A[] . Output Format Print the value

View Solution →

Waiter

You are a waiter at a party. There is a pile of numbered plates. Create an empty answers array. At each iteration, i, remove each plate from the top of the stack in order. Determine if the number on the plate is evenly divisible ith the prime number. If it is, stack it in pile Bi. Otherwise, stack it in stack Ai. Store the values Bi in from top to bottom in answers. In the next iteration, do the

View Solution →

Queue using Two Stacks

A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed from the front and new elements to be added to the rear. This is called a First-In-First-Out (FIFO) data structure because the first element added to the queue (i.e., the one that has been waiting the longest) is always the first one to be removed. A basic que

View Solution →

Castle on the Grid

You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and a goal, determine the minmum number of moves to get to the goal. Function Description Complete the minimumMoves function in the editor. minimumMoves has the following parameter(s):

View Solution →