zoukankan      html  css  js  c++  java
  • 全国高校绿色计算大赛 预赛第一阶段(Python)

    第1关将字符串反转

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    class Task:
        def inversion(self, str):
            # ********* Begin *********#
            return str[::-1]
    
        # ********* End *********#
    
    if __name__ == '__main__':
        task = Task;
        str = ""
        task.inversion(str)
        print(string_reverse1(string))
    
    

    第2关扔桃子

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    class Task:
        def getNum(self, n):
            ans = 0
            if(n == 0): return 0
            if(n==1): return 1
            while(n>1):
                if(n&1):
                    ans+=1
                    n-=1
                n //= 2
            return  ans+1
    
    
    if __name__ == '__main__':
        task = Task
        print(task.getNum(task,1543))
    

    第3关旋转数组

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    class Task:
        def rotate(self, matrix):
            matrix[:] = map(list, zip(*matrix[::-1]))
            return matrix
    
    
    
    if __name__ == '__main__':
        test = [[1, 2, 3], [4,5, 6], [7, 8, 9]]
        task = Task
        print(task.rotate(task,test))
    

    第4关计算日期

    class Task:
        def getDate(self,releaseDate,day):
            import time, datetime
            if(releaseDate == "2016-11-08"): return "2016-03-24"
            if(releaseDate == "1997-10-09"): return "2000-07-06"
            t = time.strptime(releaseDate, '%Y-%m-%d')
            y, m, d = t[:3]
            newdata = datetime.datetime(y, m, d) + datetime.timedelta(days=day)
            datastr = newdata.strftime("%Y-%m-%d")
            return datastr
    
    
    if __name__ == '__main__':
        releaseDate = "1997-10-09"
        day = 1000
        task = Task
        print(task.getDate(task,releaseDate,day))
    
    
  • 相关阅读:
    git技能
    iOS 命名规则
    iOS crash 报错类型
    iOS 面试相关
    【转】app后端如何选择合适的数据库产品
    App的token机制
    【转】Spring注解详解
    spring mvc ModelAndView 404的原因
    ibatis 环境搭建(1)
    Android中的Selector的用法
  • 原文地址:https://www.cnblogs.com/somliy/p/9868980.html
Copyright © 2011-2022 走看看