Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time
- def main():
- print getFormattedResult(
- filter( lambda date: date != None and int(date[0]) in range(2000,3000),
- map( removeNonDates,
- getCombinations(
- map( int, sys.stdin.readline().strip('\n').split('/'))
- )
- )
- ) , lambda date: "%d-%.2d-%.2d" % (int(date[0]), int(date[1]), int(date[2]))
- )
- def getFormattedResult(legalDates, formatter):
- if legalDates:
- return formatter(sorted(legalDates)[0])
- else:
- return date.strip('\n') + " is illegal"
- def removeNonDates(date):
- if date[0] < 1000:
- date[0] = date[0] + 2000
- dateStrings = map(str, date)
- try:
- time.strptime('-'.join(dateStrings), '%Y-%m-%d')
- return date
- except:
- pass
- def getCombinations(values):
- a, b, c = values
- return [[a, b, c], [a, c, b], [b, a, c], [b, c, a], [c, a, b], [c, b, a]]
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment