Skip to content

Instantly share code, notes, and snippets.

@shinux
Last active August 29, 2015 14:25
Show Gist options
  • Save shinux/0e459efb138688717b19 to your computer and use it in GitHub Desktop.
Save shinux/0e459efb138688717b19 to your computer and use it in GitHub Desktop.
计算之道,京东/人人场,第一题 python2.7.9解。
import datetime
base_dict = {
'0': 6,
'1': 2,
'2': 5,
'3': 5,
'4': 4,
'5': 5,
'6': 6,
'7': 3,
'8': 7,
'9': 6}
group_number = input()
total_list = []
__i = 0
while True:
total_list.append(input())
__i += 1
if __i >= group_number * 2:
break
for x, y in zip(*[iter(total_list)]*2):
# x is start time
# y is endtime number
x = str(x)
start_time = datetime.date(int(x[:4]), int(x[4:6]), int(x[6:]))
endtime = start_time
while endtime < datetime.date(2999, 12, 31):
endtime = endtime + datetime.timedelta(days=1)
_string = str(endtime.year) + '%02d' % endtime.month + '%02d' % endtime.day
total = 0
for i in _string:
total += base_dict[i]
if total == y:
print((endtime - start_time).days)
break
if endtime >= datetime.date(2999, 12, 31):
print('-1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment