forked from sowon-dev/AlgorithmStudy_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryFine.java
More file actions
38 lines (36 loc) ยท 1.48 KB
/
LibraryFine.java
File metadata and controls
38 lines (36 loc) ยท 1.48 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
package hackerrank;
public class LibraryFine {
static int libraryFine(int d1, int m1, int y1, int d2, int m2, int y2) {
// ์ฑ
๋ฐ๋ฉ์ ๋์ผ๋
์์์ ํ๋ฃจ ๋ฆ์ ๊ฒฝ์ฐ ๋งค์ผ 15์์ฉ ๊ณผ๊ธ
// ์ฑ
๋ฐ๋ฉ์ ๋์ผ๋
์์ ํ ๋ฌ์ด ๋ฆ์ ๊ฒฝ์ฐ ๋งค์ 500์์ฉ ๊ณผ๊ธ
// ์ฑ
๋ฐ๋ฉ์ ํด๋น ๋
์ ๋์ด๋ฒ๋ฆฐ ๊ฒฝ์ฐ 10000์ ๊ณผ๊ธ
//sol1
/*
if(y1 >= y2 && m1 == m2 && d1 > d2){
return (d1-d2)*15;
}else if(y1 == y2 && m1 > m2){
return (m1-m2)*500;
}else if(y1 >= y2){
return (y1-y2)*10000;
}
return 0;
*/
//sol2
if (y1 > y2) { return 10000; }
if (m1 > m2 && y1 == y2) { return 500 * (m1 - m2); }
if (d1 > d2 && m1 == m2 && y1 == y2) { return 15 * (d1 - d2); }
return 0;
}
public static void main(String[] args) {
System.out.println(libraryFine(9,6,2015,6,6,2015)+", ans: 45");
System.out.println(libraryFine(9,6,2015,6,6,2016)+", ans: 0");
System.out.println(libraryFine(2,5,2015,30,5,2015)+", ans: 0");
System.out.println(libraryFine(2,7,1014,1,1,1015)+", ans: 0");
System.out.println(libraryFine(2,6,2014,5,7,2014)+", ans: 0");
System.out.println(libraryFine(2,7,1014,1,1,1014)+", ans: 3000");
System.out.println(libraryFine(2,7,2015,1,2,2014)+", ans: 10000");
System.out.println(libraryFine(1,1,2001,1,2,2000)+", ans: 10000");
System.out.println(libraryFine(31,8,2004,20,1,2004)+", ans: 3500");
System.out.println(libraryFine(31,5,2014,1,5,2014)+", ans: 450");
}
}