Hackerrank – Problem Statement
A description of the problem can be found on Hackerrank.
Solution
Look at the implementation. The steps are in problem description.
I created solution in:
All solutions are also available on my GitHub profile.
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 |
object solution extends App { val sc = new java.util.Scanner (System.in) val year = sc.nextInt val output = if (year == 1918) "26.09.1918" else if (((year <= 1917) && (year%4 == 0)) || ((year%400 == 0) || ((year%4 ==0) & (year%100 != 0)))) "12.09." + year else "13.09." + year println(output) } |
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.util.*; public class Solution { static String solve(int year) { if (year == 1918) return "26.09.1918"; else if (((year <= 1917) && (year%4 == 0)) || ((year%400 == 0) || ((year%4 ==0) & (year%100 != 0)))) return "12.09." + year; else return "13.09." + year; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int year = in.nextInt(); String result = solve(year); System.out.println(result); } } |
Javascript
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 |
process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function solve(year){ if (year == 1918) return "26.09.1918"; else if (((year <= 1917) && (year%4 == 0)) || ((year%400 == 0) || ((year%4 ==0) & (year%100 != 0)))) return "12.09." + year; else return "13.09." + year; } function main() { var year = parseInt(readLine()); var result = solve(year); process.stdout.write(""+result+"\n"); } |