zoukankan      html  css  js  c++  java
  • PTA的Python练习题(十六)

    第4章-15 换硬币

    挺难的,这里学到一个range的用法:

    也就是说range函数能实现顺序和倒序,取决于step是正是负

    count = 0
    x = int(input())
    a = x // 5          
    for m in range(a,0,-1):
        b = (x - (m * 5)) // 2     
        for n in range(b,0,-1):
            c = x - (5 * m) - (2 * n)
            if m > 0 and n > 0 and c > 0:
                print("fen5:{}, fen2:{}, fen1:{}, total:{}".format(m,n,c,m + n + c))
                count += 1
     
    print("count = {}".format(count))

    第4章-16 jmu-python-判断是否构成三角形

    a,b,c=map(int,input().split())
    if a+b>c and a+c>b:
        print('yes')
    else:
        print('no')

    第4章-17 水仙花数

    a=int(input())
    for i1 in range(1,10):
        for i2 in range(0,10):
            for i3 in range(0,10):
              if a==3:
                 total=i1*100+i2*10+i3*1
                 if (total==i1**3+i2**3+i3**3):
                    print('{}'.format(total))

    问题是这里没法算4位和5位的水仙花数

    参考别人的代码:

    import math
    n=int(input())
    for i in range(int(math.pow(10,n-1)),int(math.pow(10,n))):
        sum=0
        j=i
        while(j>=1):
            sum=sum+math.pow(j%10,n)
            j=j//10
        if(sum==i):
            print('{:d}'.format(i))

    看不太懂代码是用什么来算的

    [Sign]做不出ctf题的时候很痛苦,你只能眼睁睁看着其他人领先你
  • 相关阅读:
    mysql的常用查询创建命令
    maven的简介
    google guava
    分库分表的情况下生成全局唯一的ID
    书单
    MD5Util
    UUID生成工具
    nodejs学习笔记三——nodejs使用富文本插件ueditor
    nodejs学习笔记二——链接mongodb
    mongodb 安装
  • 原文地址:https://www.cnblogs.com/echoDetected/p/12344889.html
Copyright © 2011-2022 走看看