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))
    
    
  • 相关阅读:
    矩阵距离
    CF409D Big Data
    AT2685 i18n
    P3366 【模板】最小生成树
    P3367 【模板】并查集
    ISBN(洛谷P1055)
    关于数组
    0021---一元一次方程
    0020---求圆锥体积
    0019---求圆台的体积
  • 原文地址:https://www.cnblogs.com/somliy/p/9868980.html
Copyright © 2011-2022 走看看