Skip to content
Programmingoneonone
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

HackerRank Day of the Programmer problem solution

YASH PAL, 31 July 20249 August 2024

In this Day of the Programmer problem you have Given a year, y, find the date of the 256th day of that year according to the official Russian calendar during that year. Then print it in the format dd.mm.yyyy, where dd is the two-digit day, mm is the two-digit month, and yyyy is y.

Hackerrank day of the programmer solution
Hackerrank day of the programmer solution

Topics we are covering

Toggle
  • Problem solution in Python programming.
  • Problem solution in Java Programming.
    • Problem solution in C++ programming.
    • Problem solution in C programming.
    • Problem solution in JavaScript programming.

Problem solution in Python programming.

#!/bin/python3

import sys


y = int(input().strip())
count=0
if(y>1918 and y<=2700):
    if(y%400==0 or (y%4==0 and y%100!=0)):
        count=1
    if(count==1):
        print('12.09.'+str(y))
    else:
        print('13.09.'+str(y))
if(y<1918 and y>=1700):
    if(y%4==0):
        count=1
    if(count==1):
        print('12.09.'+str(y))
    else:
        print('13.09.'+str(y))
if(y==1918):
    print('26.09.1918')

 

Problem solution in Java Programming.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static int daysInFeb(int year){
        if(year == 1918){
            return 15;
        } else if (year < 1918) {
            if (year % 4 == 0) {
                return 29;
            } else{
                return 28;
            }
        } else { //year > 1918
            if (year % 400 == 0){
                return 29;
            } else if (year % 100 == 0){
                return 28;
            } else if (year % 4 == 0){
                return 29;
            } else {
                return 28;
            }
        }
    }
    
    
    public static int daysInMonth(int month, int year){
        if (month == 2) return daysInFeb(year);
        else if (Arrays.asList(1,3,5,7,8,10,12).contains(month)){
            return 31;
        } else return 30;
    }
    
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int year = in.nextInt();
        // your code goes here
        int month = 0;
        int dayssofar = 0;
        while (dayssofar <= 256){
            month++;
            dayssofar += daysInMonth(month,year);
        }
        int day = daysInMonth(month,year);
        if (month == 2 && year == 1918) day += 13;
        while (dayssofar > 256) {
            day--;
            dayssofar--;
        }
        
        System.out.format("%02d.%02d.%04d",day,month,year);
        
    }
}

 

Problem solution in C++ programming.

#include <bits/stdc++.h>

using namespace std;

int main(){
    int y;
    cin >> y;
    if(y<1918){
        if(y%4==0)cout<<"12.09."<<y<<endl;
        else cout<<"13.09."<<y<<endl;
    }
    else if(y==1918){
         cout<<"26.09."<<y<<endl;
    }
    else{
        if(y%400==0){
            cout<<"12.09."<<y<<endl;
        }
        else if(y%4==0&&y%100!=0){
            cout<<"12.09."<<y<<endl;
        }
        else cout<<"13.09."<<y<<endl;
    }
    // your code goes here
    return 0;
}

 

Problem solution in C programming.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main()
{
    int y,leap; 
    scanf("%d",&y);
    leap=0;
    if (y % 4 == 0) leap=1;
    if (y > 1918)
    {
    if (y % 100 == 0) leap=0;
    if (y % 400 == 0) leap=1;
    }
    if (y != 1918) 
    {
        if (leap == 0) printf("13.09.%dn",y);
        else printf("12.09.%dn",y);
    }
    else printf("26.09.%dn",y);
    // your code goes here
    return 0;
}

 

Problem solution in JavaScript programming.

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 main() {
    var y = parseInt(readLine());
    var leap = 0; //make 1 if it is a leap year...remove a day
    if(y < 1918){
        if(y%4 === 0){leap = -1}
        console.log(13 + leap + ".09." + y);
    }else if(y > 1918){
        if(y%4 === 0 && y%100 !== 0 || y%400 === 0){leap = -1};
        console.log(13 + leap + ".09." + y);
    }else{ //case for 1918
        console.log("26.09.1918");
    }
}

 

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes