Problem Statement
The Head Librarian at a library wants you to make a program that calculates the fine for returning the book after the return date. You are given the actual and the expected return dates. Calculate the fine as follows:
- If the book is returned on or before the expected return date, no fine will be charged, in other words fine is 0.
- If the book is returned in the same month as the expected return date, Fine =
15 Hackos× Number of late days - If the book is not returned in the same month but in the same year as the expected return date, Fine =
500 Hackos× Number of late months - If the book is not returned in the same year, the fine is fixed at
10000 Hackos.
Input Format
You are given the actual and the expected return dates in D M Y format respectively. There are two lines of input. The first line contains the D M Y values for the actual return date and the next line contains the D M Y values for the expected return date.
Constraints
1≤D≤31
1≤M≤12
1≤Y≤3000
Output Format
Output a single value equal to the fine.
Sample Input
9 6 2015
6 6 2015
Sample Output
45
Explanation
Since the actual date is 3 days later than expected, fine is calculated as 15×3=45 Hackos.
Solution:-
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int AD,ED,AM,EM,AY,EY;
int D,M,Y,Fine=0;
scanf("%d %d %d",&AD,&AM,&AY);
scanf("%d %d %d",&ED,&EM,&EY);
if((1<=AD<=31 && 1<=AM<=12 && 1<=AY<=3000)||(1<=ED<=31 && 1<=EM<=12 && 1<=EY<=3000))
{
Y=AY-EY;
M=AM-EM;
D=AD-ED;
if(Y<0)
{
printf("0");
return 0;
}
if(Y==0 && M<0)
{
printf("0");
return 0;
}
if(Y==0 && M<=0 && D<0)
{
printf("0");
return 0;
}
if(Y>0)
{
printf("10000");
return 0;
}
if(M==0)
{
printf("%d",(D*15));
return 0;
}
if(Y==0 && M>0)
{
printf("%d",(M*500));
}
}
return 0;
}