#!/usr/bin/python2.7 # -*- coding: utf-8 -*- ''' 2012-02-18 programmeerimisvõistlus Ülesanne: Kino - testid @author: Indrek Jentson ''' import datetime ''' #1 - 01 10 / lõpus S1 = [('2012-01-01','2012-01-03'),('2012-01-05','2012-01-07')] S2 = [('2012-01-03','2012-01-04'),('2012-01-08','2012-01-09')] #2 - 01 05 / vahel S1 = [('2012-01-01','2012-01-03'),('2012-01-07','2012-01-10')] S2 = [('2012-01-03','2012-01-04'),('2012-01-08','2012-01-09')] #3 - 01 01 / alguses S1 = [('2012-02-01','2012-02-28'),('2012-04-01','2012-04-30')] S2 = [('2012-03-01','2012-03-31'),('2012-05-01','2012-05-30')] #4 - 02 29 / vahel + liigaasta S1 = [('2012-01-01','2012-02-28')] S2 = [('2012-03-05','2012-05-31')] #5 - 05 01 / vahel S1 = [('2012-01-01','2012-01-31'),('2012-03-01','2012-03-31'),('2012-05-02','2012-05-31')] S2 = [('2012-02-01','2012-02-29'),('2012-04-01','2012-04-30')] #6 - 03 31 / vahel, ainult esimese sõbra kalender S1 = [('2012-01-01','2012-03-30'),('2012-04-13','2012-06-15'),('2012-07-31','2012-08-31')] S2 = [] #7 - 02 29 / vahel + liigaasta, ainult teise sõbra kalender S1 = [] S2 = [('2012-01-01','2012-02-28'),('2012-12-25','2012-12-31')] #8 - 12 31 / lõpus S1 = [('2012-01-01','2012-10-26')] S2 = [('2012-03-06','2012-12-30')] #10 - EI SAA / ei leidu sobivat aega S1 = [('2012-01-01','2012-02-29'),('2012-08-16','2012-10-27')] S2 = [('2012-03-01','2012-08-15'),('2012-09-30','2012-12-31')] #9 - EI SAA / ei leidu sobivat aega S1 = [('2012-01-01','2012-10-26')] S2 = [('2012-03-07','2012-12-31')] ''' # Funktsioon kuupäeva teisendamiseks kuupäeva järjenumbriks aastas def kpv2num(kpv): num = kpv.toordinal()-datetime.date(2012,1,1).toordinal()+1 return num # Funktsioon kuupäeva järjenumbri aastas teisendamiseks kuupäevaks def num2kpv(num): kpv = datetime.date.fromordinal(datetime.date(2012,1,1).toordinal()+num-1) return kpv def iso2kpv(iso): kpv = datetime.date(int(iso[0:4]),int(iso[5:7]),int(iso[8:10])) return kpv def main(): MAX = 300 with open('kino.sis', 'wt') as sisend: C = [0 for x in range(1,368)] N = 0 for t in S1: k1 = iso2kpv(t[0]) k2 = iso2kpv(t[1]) k = kpv2num(k1) while k <= kpv2num(k2) and N < MAX: C[k] = 1 k += 1 N += 1 print >> sisend, '%d' % (N) i = 1 while i < 367: if C[i] == 1: kx = num2kpv(i) print >> sisend, '%02d %02d' % (int(kx.strftime('%m')), int(kx.strftime('%d'))) i += 1 C = [0 for x in range(1,368)] N = 0 for t in S2: k1 = iso2kpv(t[0]) k2 = iso2kpv(t[1]) k = kpv2num(k1) while k <= kpv2num(k2) and N < MAX: C[k] = 1 k += 1 N += 1 print >> sisend, '%d' % (N) i = 1 while i < 367: if C[i] == 1: kx = num2kpv(i) print >> sisend, '%02d %02d' % (int(kx.strftime('%m')), int(kx.strftime('%d'))) i += 1 if __name__ == '__main__': main()