Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • 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

HackerEarth Sherlock and Date problem solution

YASH PAL, 31 July 2024
In this HackerEarth Sherlock and Date problem solution Watson gives a date to Sherlock and asks him what is the date on the previous day. Help Sherlock. You are given a date in DD MM YYYY format. DD is an integer without leading zeroes. MM is one of the “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November” and “December” (all quotes for clarity). YYYY is also an integer between 1600 and 2000 without leading zeroes. You have to print the date of the previous day in the same format.
HackerEarth Sherlock and Date problem solution

HackerEarth Sherlock and Date problem solution.

import datetime
from datetime import date, timedelta


n = int(raw_input())

while n>0 :
date = raw_input();
day , month ,year = date.split();
assert(int(day)>0 & int(day)<31)
#print(day+" "+month+" "+year)
map = {
'January':1,
'February':2,
'March':3,
'April':4,
'May':5,
'June':6,
'July':7,
'August':8,
'September':9,
'October':10,
'November':11,
'December':12
}

mlist = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]

mydate = (datetime.date(int(year),map[month],int(day))) #year, month, day
#mydate =mydate+datetime.timedelta(years=40)
mydate= mydate-datetime.timedelta(days=1)
mydate = mydate.isoformat();
#print(mydate)
year ,month,day = mydate.split('-')
#print(year+" "+month+" "+day)
#print(mydate.strftime("%Y-%m-%d"))
#year = mydate.strftime("%Y");
if(int(month)<10):
month = month.strip("0");
#day = mydate.strftime("%d");
if(int(day)<10):
day = day.strip("0")
#print(month);
print(day+" "+mlist[int(month)-1] +" "+year)
n=n-1
coding problems solutions

Post navigation

Previous post
Next post

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