-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSolution6.java
More file actions
59 lines (50 loc) · 1.38 KB
/
Solution6.java
File metadata and controls
59 lines (50 loc) · 1.38 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
/**
Day of the Programmer - https://www.hackerrank.com/challenges/day-of-the-programmer/problem
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution6 {
static String solve(int year){
// Complete this function
int days = 0;
if( year == 1918 ){
//special case
days = getNumDays(false) - 13;
}
else{
if(isLeapYear(year, year < 1918 ? "J": "G")){
days = getNumDays(true);
}
else{
days = getNumDays(false);
}
}
int remDays = 256 - days;
int month = 9;
if(remDays > 30){
month += 1;
remDays = remDays - 30;
}
return remDays+"."+"0"+month+"."+year;
}
static int getNumDays(boolean isLeap){
return isLeap ? 244 : 243;
}
static boolean isLeapYear(int year, String calendar){
if("J".equals(calendar)){
return year % 4 == 0;
}
else{
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0 );
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int year = in.nextInt();
String result = solve(year);
System.out.println(result);
}
}