As a regular, this morning I devoted myself to my passion for the Clash of Codes. The one I just finished was meant to subtract two dates, like this.
So, as a good Python apprentice, I immediately thought to reuse the components of the standard library, including timedelta, which gives a simple and concise code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
from datetime import timedelta c, s = input().split() c = c.split(':') s = s.split(':') tc = timedelta(hours = int(c[0]), minutes = int(c[1])) ts = timedelta(hours = int(s[0]), minutes = int(s[1])) td = ts - tc # To not keep the seconds, which do not interest us print(':'.join(str(td).split(':')[:2])) |
The second, and by the way the only one to have shared his code, wrote it in JavaScript. I will rest it below.
1 2 3 4 5 6 7 8 9 10 11 12 |
inputs = readline().split(' '); var C = inputs[0].split(':'); var S = inputs[1].split(':'); t1=parseInt(C[0])*60+parseInt(C[1]) t2=parseInt(S[0])*60+parseInt(S[1]) t3=Math.abs(t1-t2) h=Math.floor(t3/60) m=t3%60 if(m.toString().length==1)m='0'+m print(h+':'+m); |
Nothing special, but there is no picture, the standard Python library is really dense and practical, while JavaScript is really lacking. I love Python