Skip to content

Instantly share code, notes, and snippets.

@al1b
Created September 23, 2016 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save al1b/75a186b64b843a49747576731a15eea4 to your computer and use it in GitHub Desktop.
Save al1b/75a186b64b843a49747576731a15eea4 to your computer and use it in GitHub Desktop.
/*
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