PTA的Python练习题(十六)
2024-09-06 02:47:54
第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))
看不太懂代码是用什么来算的
最新文章
- linux添加自定义的命令!
- Matlab的68个小常识
- Linux更改主机名的最简单方法
- MySql 分页
- free 堡垒机
- SqlDbHelper备份,做项目时方便应用(目前不太全,把自己项目中的逐渐转移过来)
- Windows服务程序的原理及实现(服务分为WIN32服务和系统服务)
- 微信支付 v 3.3.6
- C语言实现快速排序法(分治法)
- [Noi2016]国王饮水记
- React-组件的生命周期详解(含React16版本)
- node版本升级参考
- python练习题-day8
- HTML5:表单提交
- js乱码问题解决
- Exp02
- 解题:JSOI 2016 最佳团体
- [Web] Web请求过程之一:HTTP
- JAVA随笔(二)
- 随机森林(Random Forest)
热门文章
- 小匠第二周期打卡笔记-Task04
- Oracle 12.2.0.1 Installation Fails With ";PRVG-0449";
- Centos6.5安装Nmap、tcpdump、mysql、tomcat、靶场WAVSEP
- 215. 数组中的第K个最大元素(TOP-K问题)
- jquery easyui combogrid Uncaught TypeError:Cannot read property
- 解决windows配置visual studio code调试golang环境问题
- IntelliJ IDEA 2017.3尚硅谷-----生成 javadoc
- C++内存管理(new operator/operator new/operator delete/placement new)
- 抽象语法树 Abstract syntax tree
- 马俊龙ansible教程分享