For exemple if I was the 20.03.2024 to go to the 20.03.2025 I wasn’t taking care of the fact that I already was in march. I wasn’t removing all days from 01.01.2024 to the 20.03.2024 and add those of 2025.
Hi everyone,
I’m trying to solve this puzzle. It seem’s i have a fine solution to me.
But after submitting my code, the ‘06 COMPLEX’ test doesn’t pass, so I’m stuck at 88%.
I havn’t hardcoded anything but i clearly miss something (enonciate doesn’t help me, it’s not really precise). Without knowing what kind of validator i need to pass, i can’t deduce what the problem is .
That’s really frustrating, do you have a sample to try another complex by my self before submitting a new proposal?
Your program must print formatted string with the number of full years and full months (if there are any greater than 0) and the total number of days between BEGIN and END dates in dd.mm.yyyy format.
Example 1:
Input:
01.01.2000
01.01.2016
Output:
16 years, total 5844 days
Example 2:
Input:
15.12.2014
14.02.2016
Output:
1 year, 1 month, total 426 days
Example 3:
Input:
01.01.2016
18.08.2016
Output:
7 months, total 230 days
Input
Line 1: A date BEGIN in dd.mm.yyyy format. Line 2: A date END in dd.mm.yyyy format.
Output
Line 1 : Formatted string presenting date difference as “YY day[s], MM month[s], total NN days”
Constraints
BEGIN ≤ END
Example
Input
01.01.2000 01.01.2016
Output
16 years, total 5844 days
WHICH IS THE SOLUTIOOOOON PLEAAAAASE! I´m a begginer programmer
The standard approach to problems s like this is:
Solve it with pen&paper.
What is the input, what is the solution, what kind of steps would you have to perform to arrive from input to solution, and finally, how would you implement it.
The penultimate part being the important one.
Which can be only unsuccessful, if you meticulously documented the parts before.
That is, how you learn how to think like a programmer.
Hey, here is my ugly python code:
I’m passing all the first tests, but it seems like i have hardcoded something ?
I tried something about the 29.02.2016 => 28.02.2017.
I know there is a better way to write, but i’m beginning with python
Could someone give me a hint on what’s wrong ?
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
begin = input().split('.')
end = input().split('.')
def bissextile(year):
if (not year%4 and year%100) or not year%400:
return True
return False
m31=[1,3,5,7,8,10,12]
m30=[4,6,9,11]
d1 = int(begin[0])
d2 = int(end[0])
m1 = int(begin[1])
m2 = int(end[1])
y1 = int(begin[2])
y2 = int(end[2])
d=0
m=0
y=0
if d1==29 and m1==2 and d2==28 and m2==2:
d1=28
y1+=1
m=+11
d+=365
i=0
if m1 in m31:
i=31
elif m1 in m30:
i=30
else:
if bissextile(y1):
i=29
else:
i=28
while(d1!= d2):
d1+=1
d+=1
if d1 > i:
d1%=i
m1+=1
if m1>12:
m1%=12
y1+=1
while(m1!=m2):
j=0
if m1 in m31:
j=31
elif m1 in m30:
j=30
else:
if bissextile(y1):
j=29
else:
j=28
m1+=1
m+=1
d+=j
if m1==13:
m1%=12
y1+=1
while(y1!=y2):
if bissextile(y1):
d+=366
else:
d+=365
y1+=1
y+=1
if y>1:
print(f'{y} years, ', end='')
elif y==1:
print(f'{y} year, ', end='')
if m>1:
print(f'{m} months, ', end='')
elif m==1:
print(f'{m} month, ', end='')
print(f'total {d} days')