Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
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

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes