Last active
October 1, 2015 04:51
-
-
Save maderaka/862b2da8f0295e318977 to your computer and use it in GitHub Desktop.
A solution for fixing a librarian's problem (source of problem : 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
package main | |
import "fmt" | |
const( | |
FINE_DAY = 15 | |
FINE_MONTH = 500 | |
FINE_YEAR_FIX = 10000 | |
NO_FINE = 0 | |
) | |
func main() { | |
fine := NO_FINE | |
var adY, adM, adD int | |
var edY, edM, edD int | |
fmt.Scanf("%d %d %d", &adD, &adM, &adY) | |
fmt.Scanf("%d %d %d", &edD, &edM, &edY) | |
if adY > edY { | |
fine = FINE_YEAR_FIX | |
} else if adM > edM && adY == edY { | |
months := (adM - edM) | |
if months > 0 { | |
fine = months * FINE_MONTH | |
} | |
} else if adM == edM && adY == edY { | |
days := (adD - edD) | |
if days > 0 { | |
fine = days * FINE_DAY | |
} | |
} | |
fmt.Println(fine) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment