Created
June 13, 2016 12:19
-
-
Save hiterm/7db83f73412f667a923a8575f26d0dda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding:utf-8 | |
import re | |
import datetime | |
class Ticket: | |
def __init__(self, name, start, end): | |
self.name = name | |
self.start = start | |
self.end = end | |
# 2/29があったので、閏年にしておく | |
year = 2016 | |
# ファイル読み込み | |
tickets_temp = [] | |
for line in open('tickets.txt', 'r'): | |
tickets_temp.append(re.split('[ -]', line.rstrip("\r\n"))) | |
tickets = [] | |
for item in tickets_temp: | |
arr1 = item[1].split("/") | |
arr2 = item[2].split("/") | |
s = datetime.date(year, int(arr1[0]), int(arr1[1])) | |
e = datetime.date(year, int(arr2[0]), int(arr2[1])) | |
tickets.append( Ticket(item[0], s, e) ) | |
# 終わりの日付でソート | |
tickets.sort( key = lambda item: item.end) | |
# 解答となるプランを作る | |
plan = [tickets[0]] | |
for item in tickets: | |
if plan[-1].end < item.start: | |
plan.append(item) | |
for item in plan: | |
print "%s: %s - %s" % (item.name, item.start, item.end) | |
print "number of tickets: %d" % len(plan) | |
print "answer:" | |
print len(plan), | |
for item in sorted(plan): | |
print item.name, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment