Skip to content

Instantly share code, notes, and snippets.

@al1b al1b/library-fine.cs
Created Sep 23, 2016

Embed
What would you like to do?
/*
Author: Ali Bahraminezhad
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).
https://www.hackerrank.com/challenges/library-fine
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main(String[] args)
{
string[] tokens_d1 = Console.ReadLine().Split(' ');
int d1 = Convert.ToInt32(tokens_d1[0]);
int m1 = Convert.ToInt32(tokens_d1[1]);
int y1 = Convert.ToInt32(tokens_d1[2]);
string[] tokens_d2 = Console.ReadLine().Split(' ');
int d2 = Convert.ToInt32(tokens_d2[0]);
int m2 = Convert.ToInt32(tokens_d2[1]);
int y2 = Convert.ToInt32(tokens_d2[2]);
if (y1 < y2 || (y1 == y2 && m1 < m2) || (y1 == y2 && m1 == m2 && d1 <= d2)) // No Fine
Console.WriteLine("0");
else if (y1 == y2 && m1 == m2 && d1 > d2) // Fine per day
Console.WriteLine((d1 - d2) * 15);
else if (y1 == y2 && m1 > m2) // Fine per month
Console.WriteLine((m1 - m2) * 500);
else
Console.WriteLine(10000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.