zoukankan      html  css  js  c++  java
  • 输入( 年 ,月 )打印日历()

    def is_leapyear( year ):
        return True if year % 4 ==  0 and year % 100 !=  0 or year % 400 == 0 else False


    def days_year( year ):
       return 366 if is_leapyear( year ) else 365


    def days_month( year , month ):
        l = [ 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]
        u = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]
        return l[ month-1 ]if is_leapyear( year ) else u[ month-1 ]


    def get_week( year , month ):
        days = 0
        if ( 1990 <= year <= 2018 ) or ( 1 <= month <= 12 ) :
            for y in range( 1990 , year ):
                days += days_year( y )
            for m in range( 1 , month ):
                days += days_month( year , m )
            return ( days + 1 ) % 7
    def get_week( year , month ): days = 0 if ( 1990 <= year <= 2018 ) or ( 1 <= month <= 12 ) : for y in range( 1990 , year ): days += days_year( y ) for m in range( 1 , month ): days += days_month( year , m ) return ( days + 1 ) % 7
    while True: year , month = eval( input( ' Input year and month (year , month): ' ) ) days = 0 if ( 1990 <= year <= 2018 ) or ( 1 <= month <= 12 ): print( ' {}年{}月'.format(year,month) ) print( ' 日 一 二 三 四 五 六' ) for week in range( get_week( year , month ) ): print( ' '+' ',end='' ) for day in range( 1 , days_month( year , month ) + 1 ): print( ' {: <2}'.format( day ) , end='' ) if ( day + get_week( year , month ) ) % 7 == 0 or day == days_month( year , month ) : print('') else : continue
  • 相关阅读:
    Luogu P4246 [SHOI2008]堵塞的交通(线段树+模拟)
    Luogu P2619 [国家集训队2]Tree I(WQS二分+最小生成树)
    Luogu P2042 [NOI2005]维护数列(平衡树)
    Luogu P1052 过河(dp)
    Luogu P1041 传染病控制(搜索)
    Luogu P2717 寒假作业(平衡树)
    Luogu P2822 组合数问题(前缀和)
    Luogu P2827 蚯蚓(模拟)
    随机图片测试
    Luogu P2458 [SDOI2006]保安站岗(树形dp)
  • 原文地址:https://www.cnblogs.com/TyroneYang/p/10075678.html
Copyright © 2011-2022 走看看