HackerRank Day of the Programmer Problem Solution C Solution
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
void solve(int year){
// Complete this function
char str[20] = "13.09.2017";
int num_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (year >= 1919) {
if (((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0))) {
str[1] = '2';
}
} else if (year <= 1917) {
if ((year % 4) == 0) {
str[1] = '2';
}
} else {
//year = 1918
str[0] = '2';
str[1] = '6';
}
str[6] = '0' + year / 1000;
str[7] = '0' + (year / 100) % 10;
str[8] = '0' + (year / 10) % 10;
str[9] = '0' + year % 10;
printf("%s\n", str);
}
int main() {
int year;
scanf("%d", &year);
int result_size;
solve(year);
return 0;
}
HackerRank Day of the Programmer Problem Solution JavaScript
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){
// Complete this function
var days=[31,28,31,30,31,30,31,31,30,31,30,31];
if(year===1918){
days[1]=28-13;
}
else if(year<=1917){
if(year%4===0){
days[1]=29;
}
}
else{
if(year%400===0||(year%4===0&&year%100!==0)){
days[1]=29;
}
}
var count=0,i=0;
while(count+days[i]<=256){
count+=days[i];
i++;
}
var day=256-count;
var month=i+1;
return `${day<10?'0'+day:day}.${month<10?'0'+month:month}.${year}`
}
function main() {
var year = parseInt(readLine());
var result = solve(year);
process.stdout.write(""+result+"\n");
}HackerRank Day of the Programmer Problem Solution Python
#!/bin/python3
import sys
def solve(year):
if year<1918:
if year%4==0:
d = 12
else:
d = 13
elif year>1918:
if year%400==0 or (year%4 == 0 and year%100!=0):
d = 12
else:
d =13
else:
d= 26
return '{}.09.{}'.format(d,year)
year = int(input().strip())
result = solve(year)
print(result)
0 Comments