Love丶FFC's Blog
有一类节日的日期并不是固定的,而是以“a月的第b个星期c”的形式定下来的,比如说母亲节就定为每年的五月的第二个星期日。
现在,给你a,b,c和y1, y2(1850 ≤ y1, y2 ≤ 2050),希望你输出从公元y1年到公元y2年间的每年的a月的第b个星期c的日期。
提示:关于闰年的规则:年份是400的整数倍时是闰年,否则年份是4的倍数并且不是100的倍数时是闰年,其他年份都不是闰年。例如1900年就不是闰年,而2000年是闰年。
为了方便你推算,已知1850年1月1日是星期二。
输入包含恰好一行,有五个整数a, b, c, y1, y2。其中c=1, 2, ……, 6, 7分别表示星期一、二、……、六、日。
对于y1和y2之间的每一个年份,包括y1和y2,按照年份从小到大的顺序输出一行。
如果该年的a月第b个星期c确实存在,则以"yyyy/mm/dd"的格式输出,即输出四位数的年份,两位数的月份,两位数的日期,中间用斜杠“/”分隔,位数不足时前补零。
如果该年的a月第b个星期c并不存在,则输出"none"(不包含双引号)。
5 2 7 2014 2015
2014/05/11
2015/05/10
所有评测用例都满足:1 ≤ a ≤ 12,1 ≤ b ≤ 5,1 ≤ c ≤ 7,1850 ≤ y1, y2 ≤ 2050。
1.首先根据题目给定的1850年1月1日为星期二,算出Startyear年1月1日为星期几
2.再算出Startyear年Month月1号为星期几
3.因为每个月的星期数不尽相同,因此需要创建一个列表存放,例如2019年12月有5个星期二,4个星期三
4.遍历Month月的每一天,判断是否有符合题目条件的日期,然后根据题目要求输出
Nowday = 2 # 1850年1月1日对应星期二 # 计算该年1月1号对应星期几,与前一年的差距为365(366)%7的余数 # 例如,1850年1月1号对应星期二,1851年1月1号对应星期三,1852年1月1号对应星期四,1853年1月1号对应星期六 def distance(): global Nowday if Year % 400 == 0 or (Year % 4 == 0 and Year % 100 != 0): Nowday += 2 else: Nowday += 1 Date = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 初始化一个日期列表 Month, Week, Day, Startyear, Endyear = map(int, input().split()) # 分别输入月、周、天、起始年份、结束年份 for Year in range(1850, Startyear): distance() Nowday %= 7 # Startyear年1月1号是星期Nowday for Year in range(Startyear, Endyear + 1): temp = Nowday # 暂时存放该年的1月1号是星期几 if Year % 400 == 0 or (Year % 4 == 0 and Year % 100 != 0): Date[1] = 29 else: Date[1] = 28 Nowday = (Nowday + sum(Date[:Month - 1])) % 7 # Startyear年Month月1号是星期几 Weekday = [0, 0, 0, 0, 0, 0, 0] # 存放该月有几个星期一、星期二····· Countday, Judge = 1, False # 当前日期,标记是否有符合条件的日期 for i in range(0, Date[Month - 1]): Weekday[Nowday - 1] += 1 if Weekday[Day - 1] == Week and Nowday == Day: # 找到符合条件的日期,按题目要求输出并结束遍历 if Month < 10: Month = str('0' + str(Month)) if Countday < 10: Countday = str('0' + str(Countday)) print(str(Year) + '/' + str(Month) + '/' + str(Countday)) Judge, Month = True, int(Month) # 修改标记,将Month变为int变量 break Nowday, Countday = Nowday + 1, Countday + 1 if Nowday > 7: # 到下一星期 Nowday %= 7 if Judge == False: # 不存在符合条件的日期 print('none') Nowday = temp # 将日期重置为1月1号 distance() # 计算下一年的1月1号对应星期几
FoorryNox
where to buy cialis online It is better to have less contact with people like him if you know people and faces but do not know your heart
authentic cheap jordans
Read reviews and was a little hesitant since I had already inputted my order. to but thank god, I had no issues. decline received item in a timely matter, they are in new condition. blue jays so happy I made the purchase. Will be definitely be purchasing again.
authentic cheap jordans https://www.realjordansshoes.com/
louis vuitton outlet sale online
Read reviews and was a little hesitant since I had already inputted my order. along with but thank god, I had no issues. love the received item in a timely matter, they are in new condition. you decide so happy I made the purchase. Will be definitely be purchasing again.
louis vuitton outlet sale online https://www.louisvuittonsoutletonline.com/
Preliaf
My name is Donna Pinto no presription finasteride 69, microglia C1QA, 6
Hgnkyi
tricor usa order tricor 160mg sale buy tricor without prescription
Kdvdni
real cialis buy sildenafil 50mg online cheapest viagra
Yfjlzt
order ketotifen 1 mg generic order tofranil 75mg pills buy generic imipramine for sale
Joticn
order minoxidil generic cialis mail order ed pills online
Imxsna
acarbose 25mg for sale buy cheap precose buy fulvicin 250 mg for sale
Wfqlwc
order aspirin 75 mg online cheap buy levoflox 500mg online cheap purchase imiquad