-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary_Fine.java
More file actions
66 lines (47 loc) · 1.69 KB
/
Library_Fine.java
File metadata and controls
66 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Problem Link: https://www.hackerrank.com/challenges/library-fine/problem
*/
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
// Complete the libraryFine function below.
static int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
int fine =0;
if(y2 != y1 && y2<y1){
fine += 10000;
}else if(m2 != m1 && m2<m1){
if(y2 == y1 ) {
fine += Math.abs(m1-m2)*500;
}
}else if(d2 != d1 && d2<d1){
if(m2 == m1 && y2==y1 ) {
fine += (d1 - d2) * 15;
}
}else{
fine = 0;
}
return fine;
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
String[] d1M1Y1 = scanner.nextLine().split(" ");
int d1 = Integer.parseInt(d1M1Y1[0]);
int m1 = Integer.parseInt(d1M1Y1[1]);
int y1 = Integer.parseInt(d1M1Y1[2]);
String[] d2M2Y2 = scanner.nextLine().split(" ");
int d2 = Integer.parseInt(d2M2Y2[0]);
int m2 = Integer.parseInt(d2M2Y2[1]);
int y2 = Integer.parseInt(d2M2Y2[2]);
int result = libraryFine(d1, m1, y1, d2, m2, y2);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedWriter.close();
scanner.close();
}
}