Created
September 23, 2016 16:44
-
-
Save al1b/75a186b64b843a49747576731a15eea4 to your computer and use it in GitHub Desktop.
HackerRank Library Fine: https://www.hackerrank.com/challenges/library-fine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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