bai-python-hwc 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bai_python_hwc/__init__.py +46 -0
- bai_python_hwc/answers/hwc101.py +38 -0
- bai_python_hwc/answers/hwc103.py +52 -0
- bai_python_hwc/answers/hwc104.py +45 -0
- bai_python_hwc/answers/hwc105.py +45 -0
- bai_python_hwc/answers/hwc106.py +56 -0
- bai_python_hwc/answers/hwc107.py +49 -0
- bai_python_hwc/answers/hwc108.py +45 -0
- bai_python_hwc/answers/hwc109.py +50 -0
- bai_python_hwc/answers/hwc110.py +42 -0
- bai_python_hwc/answers/hwc111.py +47 -0
- bai_python_hwc/answers/hwc112.py +42 -0
- bai_python_hwc/answers/hwc113.py +58 -0
- bai_python_hwc/answers/hwc114.py +58 -0
- bai_python_hwc/answers/hwc115.py +38 -0
- bai_python_hwc/answers/hwc116.py +44 -0
- bai_python_hwc/answers/hwc117.py +46 -0
- bai_python_hwc/answers/hwc118.py +47 -0
- bai_python_hwc/answers/hwc119.py +44 -0
- bai_python_hwc/answers/hwc120.py +41 -0
- bai_python_hwc/answers/hwc121.py +50 -0
- bai_python_hwc/answers/hwc122.py +54 -0
- bai_python_hwc/answers/hwc123.py +43 -0
- bai_python_hwc/answers/hwc124.py +41 -0
- bai_python_hwc/answers/hwc125.py +52 -0
- bai_python_hwc/answers/hwc126.py +40 -0
- bai_python_hwc/answers/hwc127.py +41 -0
- bai_python_hwc/answers/hwc128.py +39 -0
- bai_python_hwc/answers/hwc130.py +46 -0
- bai_python_hwc/answers/hwc131.py +46 -0
- bai_python_hwc/answers/hwc132.py +38 -0
- bai_python_hwc/answers/hwc133.py +61 -0
- bai_python_hwc/answers/hwc134.py +45 -0
- bai_python_hwc/answers/hwc135.py +49 -0
- bai_python_hwc/answers/hwc136.py +43 -0
- bai_python_hwc/answers/hwc201.py +47 -0
- bai_python_hwc/answers/hwc202.py +47 -0
- bai_python_hwc/answers/hwc203.py +48 -0
- bai_python_hwc/answers/hwc204.py +61 -0
- bai_python_hwc/answers/hwc205.py +56 -0
- bai_python_hwc/answers/hwc206.py +53 -0
- bai_python_hwc/answers/hwc207.py +43 -0
- bai_python_hwc/answers/hwc208.py +57 -0
- bai_python_hwc/answers/hwc209.py +42 -0
- bai_python_hwc/answers/hwc210.py +46 -0
- bai_python_hwc/answers/hwc211.py +62 -0
- bai_python_hwc/answers/hwc212.py +58 -0
- bai_python_hwc/answers/hwc213.py +54 -0
- bai_python_hwc/answers/hwc214.py +55 -0
- bai_python_hwc/answers/hwc215.py +53 -0
- bai_python_hwc/answers/hwc216.py +50 -0
- bai_python_hwc/answers/hwc217.py +38 -0
- bai_python_hwc/answers/hwc218.py +44 -0
- bai_python_hwc/answers/hwc219.py +49 -0
- bai_python_hwc/answers/hwc220.py +58 -0
- bai_python_hwc/answers/hwc221.py +49 -0
- bai_python_hwc/answers/hwc222.py +48 -0
- bai_python_hwc/answers/hwc223.py +39 -0
- bai_python_hwc/answers/hwc224.py +47 -0
- bai_python_hwc/answers/hwc225.py +50 -0
- bai_python_hwc/answers/hwc226.py +41 -0
- bai_python_hwc/answers/hwc227.py +40 -0
- bai_python_hwc/answers/hwc228.py +41 -0
- bai_python_hwc/answers/hwc229.py +51 -0
- bai_python_hwc/answers/hwc230.py +41 -0
- bai_python_hwc/answers/hwc231.py +39 -0
- bai_python_hwc/answers/hwc232.py +44 -0
- bai_python_hwc/answers/hwc233.py +49 -0
- bai_python_hwc/answers/hwc234.py +52 -0
- bai_python_hwc/answers/hwc235.py +45 -0
- bai_python_hwc/answers/hwc236.py +53 -0
- bai_python_hwc/answers/hwc237.py +56 -0
- bai_python_hwc/answers/hwc238.py +52 -0
- bai_python_hwc/answers/hwc239.py +60 -0
- bai_python_hwc/answers/hwc240.py +45 -0
- bai_python_hwc/answers/hwc241.py +48 -0
- bai_python_hwc/answers/hwc242.py +50 -0
- bai_python_hwc/answers/hwc243.py +61 -0
- bai_python_hwc/answers/hwc244.py +61 -0
- bai_python_hwc/answers/hwc245.py +47 -0
- bai_python_hwc/answers/hwc246.py +52 -0
- bai_python_hwc/answers/hwc247.py +76 -0
- bai_python_hwc/answers/hwc301.py +44 -0
- bai_python_hwc/answers/hwc302.py +53 -0
- bai_python_hwc/answers/hwc303.py +63 -0
- bai_python_hwc/answers/hwc304.py +56 -0
- bai_python_hwc/answers/hwc305.py +59 -0
- bai_python_hwc/answers/hwc306.py +60 -0
- bai_python_hwc/answers/hwc307.py +50 -0
- bai_python_hwc/answers/hwc308.py +59 -0
- bai_python_hwc/answers/hwc309.py +48 -0
- bai_python_hwc/answers/hwc310.py +38 -0
- bai_python_hwc/answers/hwc311.py +48 -0
- bai_python_hwc/answers/hwc312.py +49 -0
- bai_python_hwc/answers/hwc313.py +54 -0
- bai_python_hwc/answers/hwc314.py +49 -0
- bai_python_hwc/answers/hwc315.py +63 -0
- bai_python_hwc/answers/hwc316.py +65 -0
- bai_python_hwc/answers/hwc317.py +57 -0
- bai_python_hwc/answers/hwc318.py +55 -0
- bai_python_hwc/answers/hwc319.py +50 -0
- bai_python_hwc/answers/hwc320.py +84 -0
- bai_python_hwc/answers/hwc321.py +49 -0
- bai_python_hwc/answers/hwc322.py +49 -0
- bai_python_hwc/answers/hwc323.py +69 -0
- bai_python_hwc/answers/hwc324.py +66 -0
- bai_python_hwc/answers/hwc325.py +49 -0
- bai_python_hwc/answers/hwc326.py +53 -0
- bai_python_hwc/answers/hwc327.py +38 -0
- bai_python_hwc/answers/hwc328.py +50 -0
- bai_python_hwc/answers/hwc329.py +59 -0
- bai_python_hwc/answers/hwc330.py +45 -0
- bai_python_hwc/answers/hwc332.py +57 -0
- bai_python_hwc/answers/hwc401.py +50 -0
- bai_python_hwc/answers/hwc402.py +43 -0
- bai_python_hwc/answers/hwc403.py +73 -0
- bai_python_hwc/answers/hwc404.py +51 -0
- bai_python_hwc/answers/hwc405.py +62 -0
- bai_python_hwc/answers/hwc406.py +66 -0
- bai_python_hwc/answers/hwc407.py +49 -0
- bai_python_hwc/answers/hwc408.py +67 -0
- bai_python_hwc/answers/hwc409.py +51 -0
- bai_python_hwc/answers/hwc410.py +52 -0
- bai_python_hwc/answers/hwc411.py +57 -0
- bai_python_hwc/answers/hwc412.py +53 -0
- bai_python_hwc/answers/hwc413.py +65 -0
- bai_python_hwc/answers/hwc414.py +50 -0
- bai_python_hwc/answers/hwc415.py +61 -0
- bai_python_hwc/answers/hwc416.py +69 -0
- bai_python_hwc/answers/hwc418.py +47 -0
- bai_python_hwc/answers/hwc419.py +62 -0
- bai_python_hwc/answers/hwc421.py +51 -0
- bai_python_hwc/answers/hwc424.py +48 -0
- bai_python_hwc/answers/hwc501.py +63 -0
- bai_python_hwc/answers/hwc502.py +69 -0
- bai_python_hwc/answers/hwc503.py +75 -0
- bai_python_hwc/answers/hwc504.py +52 -0
- bai_python_hwc/answers/hwc505.py +63 -0
- bai_python_hwc/answers/hwc506.py +61 -0
- bai_python_hwc/answers/hwc508.py +60 -0
- bai_python_hwc/answers/hwc509.py +85 -0
- bai_python_hwc/answers/hwc510.py +56 -0
- bai_python_hwc/answers/hwc511.py +52 -0
- bai_python_hwc/answers/hwc513.py +63 -0
- bai_python_hwc/answers/hwc514.py +74 -0
- bai_python_hwc/answers/hwc515.py +83 -0
- bai_python_hwc/answers/hwc516.py +67 -0
- bai_python_hwc/answers/hwc517.py +46 -0
- bai_python_hwc/answers/hwc520.py +54 -0
- bai_python_hwc/answers/hwc526.py +58 -0
- bai_python_hwc/attachments/hwc424.pdf +0 -0
- bai_python_hwc/attachments/hwc501.pdf +0 -0
- bai_python_hwc/questions/hwc101.txt +17 -0
- bai_python_hwc/questions/hwc103.txt +27 -0
- bai_python_hwc/questions/hwc104.txt +22 -0
- bai_python_hwc/questions/hwc105.txt +23 -0
- bai_python_hwc/questions/hwc106.txt +26 -0
- bai_python_hwc/questions/hwc107.txt +29 -0
- bai_python_hwc/questions/hwc108.txt +18 -0
- bai_python_hwc/questions/hwc109.txt +24 -0
- bai_python_hwc/questions/hwc110.txt +16 -0
- bai_python_hwc/questions/hwc111.txt +25 -0
- bai_python_hwc/questions/hwc112.txt +13 -0
- bai_python_hwc/questions/hwc113.txt +28 -0
- bai_python_hwc/questions/hwc114.txt +35 -0
- bai_python_hwc/questions/hwc115.txt +15 -0
- bai_python_hwc/questions/hwc116.txt +13 -0
- bai_python_hwc/questions/hwc117.txt +14 -0
- bai_python_hwc/questions/hwc118.txt +25 -0
- bai_python_hwc/questions/hwc119.txt +18 -0
- bai_python_hwc/questions/hwc120.txt +23 -0
- bai_python_hwc/questions/hwc121.txt +26 -0
- bai_python_hwc/questions/hwc122.txt +21 -0
- bai_python_hwc/questions/hwc123.txt +21 -0
- bai_python_hwc/questions/hwc124.txt +19 -0
- bai_python_hwc/questions/hwc125.txt +31 -0
- bai_python_hwc/questions/hwc126.txt +18 -0
- bai_python_hwc/questions/hwc127.txt +17 -0
- bai_python_hwc/questions/hwc128.txt +14 -0
- bai_python_hwc/questions/hwc130.txt +23 -0
- bai_python_hwc/questions/hwc131.txt +19 -0
- bai_python_hwc/questions/hwc132.txt +16 -0
- bai_python_hwc/questions/hwc133.txt +39 -0
- bai_python_hwc/questions/hwc134.txt +22 -0
- bai_python_hwc/questions/hwc135.txt +29 -0
- bai_python_hwc/questions/hwc136.txt +20 -0
- bai_python_hwc/questions/hwc201.txt +20 -0
- bai_python_hwc/questions/hwc202.txt +25 -0
- bai_python_hwc/questions/hwc203.txt +26 -0
- bai_python_hwc/questions/hwc204.txt +32 -0
- bai_python_hwc/questions/hwc205.txt +28 -0
- bai_python_hwc/questions/hwc206.txt +28 -0
- bai_python_hwc/questions/hwc207.txt +16 -0
- bai_python_hwc/questions/hwc208.txt +27 -0
- bai_python_hwc/questions/hwc209.txt +15 -0
- bai_python_hwc/questions/hwc210.txt +28 -0
- bai_python_hwc/questions/hwc211.txt +35 -0
- bai_python_hwc/questions/hwc212.txt +29 -0
- bai_python_hwc/questions/hwc213.txt +27 -0
- bai_python_hwc/questions/hwc214.txt +27 -0
- bai_python_hwc/questions/hwc215.txt +28 -0
- bai_python_hwc/questions/hwc216.txt +22 -0
- bai_python_hwc/questions/hwc217.txt +17 -0
- bai_python_hwc/questions/hwc218.txt +18 -0
- bai_python_hwc/questions/hwc219.txt +22 -0
- bai_python_hwc/questions/hwc220.txt +28 -0
- bai_python_hwc/questions/hwc221.txt +18 -0
- bai_python_hwc/questions/hwc222.txt +20 -0
- bai_python_hwc/questions/hwc223.txt +18 -0
- bai_python_hwc/questions/hwc224.txt +23 -0
- bai_python_hwc/questions/hwc225.txt +26 -0
- bai_python_hwc/questions/hwc226.txt +18 -0
- bai_python_hwc/questions/hwc227.txt +15 -0
- bai_python_hwc/questions/hwc228.txt +16 -0
- bai_python_hwc/questions/hwc229.txt +20 -0
- bai_python_hwc/questions/hwc230.txt +18 -0
- bai_python_hwc/questions/hwc231.txt +13 -0
- bai_python_hwc/questions/hwc232.txt +19 -0
- bai_python_hwc/questions/hwc233.txt +21 -0
- bai_python_hwc/questions/hwc234.txt +27 -0
- bai_python_hwc/questions/hwc235.txt +18 -0
- bai_python_hwc/questions/hwc236.txt +23 -0
- bai_python_hwc/questions/hwc237.txt +28 -0
- bai_python_hwc/questions/hwc238.txt +25 -0
- bai_python_hwc/questions/hwc239.txt +28 -0
- bai_python_hwc/questions/hwc240.txt +21 -0
- bai_python_hwc/questions/hwc241.txt +25 -0
- bai_python_hwc/questions/hwc242.txt +23 -0
- bai_python_hwc/questions/hwc243.txt +35 -0
- bai_python_hwc/questions/hwc244.txt +25 -0
- bai_python_hwc/questions/hwc245.txt +24 -0
- bai_python_hwc/questions/hwc246.txt +28 -0
- bai_python_hwc/questions/hwc247.txt +51 -0
- bai_python_hwc/questions/hwc301.txt +23 -0
- bai_python_hwc/questions/hwc302.txt +26 -0
- bai_python_hwc/questions/hwc303.txt +32 -0
- bai_python_hwc/questions/hwc304.txt +32 -0
- bai_python_hwc/questions/hwc305.txt +31 -0
- bai_python_hwc/questions/hwc306.txt +31 -0
- bai_python_hwc/questions/hwc307.txt +29 -0
- bai_python_hwc/questions/hwc308.txt +30 -0
- bai_python_hwc/questions/hwc309.txt +25 -0
- bai_python_hwc/questions/hwc310.txt +15 -0
- bai_python_hwc/questions/hwc311.txt +23 -0
- bai_python_hwc/questions/hwc312.txt +19 -0
- bai_python_hwc/questions/hwc313.txt +26 -0
- bai_python_hwc/questions/hwc314.txt +27 -0
- bai_python_hwc/questions/hwc315.txt +21 -0
- bai_python_hwc/questions/hwc316.txt +36 -0
- bai_python_hwc/questions/hwc317.txt +28 -0
- bai_python_hwc/questions/hwc318.txt +27 -0
- bai_python_hwc/questions/hwc319.txt +26 -0
- bai_python_hwc/questions/hwc320.txt +42 -0
- bai_python_hwc/questions/hwc321.txt +27 -0
- bai_python_hwc/questions/hwc322.txt +26 -0
- bai_python_hwc/questions/hwc323.txt +24 -0
- bai_python_hwc/questions/hwc324.txt +40 -0
- bai_python_hwc/questions/hwc325.txt +21 -0
- bai_python_hwc/questions/hwc326.txt +25 -0
- bai_python_hwc/questions/hwc327.txt +16 -0
- bai_python_hwc/questions/hwc328.txt +15 -0
- bai_python_hwc/questions/hwc329.txt +26 -0
- bai_python_hwc/questions/hwc330.txt +27 -0
- bai_python_hwc/questions/hwc332.txt +26 -0
- bai_python_hwc/questions/hwc401.txt +25 -0
- bai_python_hwc/questions/hwc402.txt +24 -0
- bai_python_hwc/questions/hwc403.txt +37 -0
- bai_python_hwc/questions/hwc404.txt +23 -0
- bai_python_hwc/questions/hwc405.txt +29 -0
- bai_python_hwc/questions/hwc406.txt +34 -0
- bai_python_hwc/questions/hwc407.txt +24 -0
- bai_python_hwc/questions/hwc408.txt +28 -0
- bai_python_hwc/questions/hwc409.txt +25 -0
- bai_python_hwc/questions/hwc410.txt +23 -0
- bai_python_hwc/questions/hwc411.txt +34 -0
- bai_python_hwc/questions/hwc412.txt +29 -0
- bai_python_hwc/questions/hwc413.txt +28 -0
- bai_python_hwc/questions/hwc414.txt +27 -0
- bai_python_hwc/questions/hwc415.txt +27 -0
- bai_python_hwc/questions/hwc416.txt +36 -0
- bai_python_hwc/questions/hwc418.txt +25 -0
- bai_python_hwc/questions/hwc419.txt +28 -0
- bai_python_hwc/questions/hwc421.txt +23 -0
- bai_python_hwc/questions/hwc424.txt +20 -0
- bai_python_hwc/questions/hwc501.txt +23 -0
- bai_python_hwc/questions/hwc502.txt +41 -0
- bai_python_hwc/questions/hwc503.txt +36 -0
- bai_python_hwc/questions/hwc504.txt +18 -0
- bai_python_hwc/questions/hwc505.txt +25 -0
- bai_python_hwc/questions/hwc506.txt +32 -0
- bai_python_hwc/questions/hwc508.txt +24 -0
- bai_python_hwc/questions/hwc509.txt +42 -0
- bai_python_hwc/questions/hwc510.txt +25 -0
- bai_python_hwc/questions/hwc511.txt +23 -0
- bai_python_hwc/questions/hwc513.txt +25 -0
- bai_python_hwc/questions/hwc514.txt +35 -0
- bai_python_hwc/questions/hwc515.txt +46 -0
- bai_python_hwc/questions/hwc516.txt +26 -0
- bai_python_hwc/questions/hwc517.txt +20 -0
- bai_python_hwc/questions/hwc520.txt +27 -0
- bai_python_hwc/questions/hwc526.txt +36 -0
- bai_python_hwc-1.0.0.dist-info/METADATA +41 -0
- bai_python_hwc-1.0.0.dist-info/RECORD +305 -0
- bai_python_hwc-1.0.0.dist-info/WHEEL +5 -0
- bai_python_hwc-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·递归考点)
|
|
15
|
+
用递归方法计算 s = 1! + 2! + 3! + ... + n! 的值,并把结果返回。约束 n >= 1。
|
|
16
|
+
提示:
|
|
17
|
+
- 阶乘递归定义:fact(n) = n * fact(n-1),fact(1) = 1,fact(0) = 1
|
|
18
|
+
- 求和可用递归也可直接累加
|
|
19
|
+
|
|
20
|
+
示例:
|
|
21
|
+
输入:n = 3
|
|
22
|
+
输出:9 # 即 1! + 2! + 3! = 1 + 2 + 6 = 9
|
|
23
|
+
|
|
24
|
+
输入:n = 5
|
|
25
|
+
输出:153 # 即 1! + 2! + 3! + 4! + 5! = 153
|
|
26
|
+
'''
|
|
27
|
+
|
|
28
|
+
# 参考答案
|
|
29
|
+
|
|
30
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
31
|
+
rlt = None
|
|
32
|
+
##########start下面可以改动
|
|
33
|
+
|
|
34
|
+
def product_and_sum(low, high):
|
|
35
|
+
# 返回区间乘积和从 low 开始的各前缀乘积之和。
|
|
36
|
+
if low == high:
|
|
37
|
+
return low, low
|
|
38
|
+
middle = (low + high) // 2
|
|
39
|
+
left_product, left_sum = product_and_sum(low, middle)
|
|
40
|
+
right_product, right_sum = product_and_sum(middle + 1, high)
|
|
41
|
+
return left_product * right_product, left_sum + left_product * right_sum
|
|
42
|
+
|
|
43
|
+
_, rlt = product_and_sum(1, n)
|
|
44
|
+
|
|
45
|
+
##########end上面可以改动
|
|
46
|
+
return rlt
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
###########下面可以修改
|
|
50
|
+
print(TEST_DO_NOT_CHANGE(3))
|
|
51
|
+
print(TEST_DO_NOT_CHANGE(5))
|
|
52
|
+
print(TEST_DO_NOT_CHANGE(10))
|
|
53
|
+
# 题号:hwc236
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·递归考点)
|
|
15
|
+
用递归方法计算 1 + 2 + 3 + ... + n 的值,并把结果返回。约束 n >= 1。
|
|
16
|
+
不允许使用 sum() 或 for/while 循环,必须用递归实现。
|
|
17
|
+
|
|
18
|
+
递归定义:
|
|
19
|
+
sum_n(1) = 1
|
|
20
|
+
sum_n(n) = n + sum_n(n-1) (n >= 2)
|
|
21
|
+
|
|
22
|
+
示例:
|
|
23
|
+
输入:n = 5
|
|
24
|
+
输出:15 # 1+2+3+4+5 = 15
|
|
25
|
+
|
|
26
|
+
输入:n = 10
|
|
27
|
+
输出:55 # 1+2+...+10 = 55
|
|
28
|
+
|
|
29
|
+
输入:n = 1
|
|
30
|
+
输出:1
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
|
|
35
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
36
|
+
rlt = None
|
|
37
|
+
##########start下面可以改动
|
|
38
|
+
|
|
39
|
+
def range_sum(low, high):
|
|
40
|
+
if low == high:
|
|
41
|
+
return low
|
|
42
|
+
middle = (low + high) // 2
|
|
43
|
+
return range_sum(low, middle) + range_sum(middle + 1, high)
|
|
44
|
+
|
|
45
|
+
rlt = range_sum(1, n)
|
|
46
|
+
|
|
47
|
+
##########end上面可以改动
|
|
48
|
+
return rlt
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
###########下面可以修改
|
|
52
|
+
print(TEST_DO_NOT_CHANGE(5))
|
|
53
|
+
print(TEST_DO_NOT_CHANGE(10))
|
|
54
|
+
print(TEST_DO_NOT_CHANGE(1))
|
|
55
|
+
print(TEST_DO_NOT_CHANGE(100))
|
|
56
|
+
# 题号:hwc237
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·字符串递归考点)
|
|
15
|
+
编写一个函数,使用递归把传入字符串 s 反转后返回。
|
|
16
|
+
不允许使用 s[::-1] 这种切片或 reversed() 内置函数,必须用递归实现。
|
|
17
|
+
提示:返回 reverse(s[1:]) + s[0],即先递归反转剩余部分,再拼接首字符。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
输入:s = "hello"
|
|
21
|
+
输出:"olleh"
|
|
22
|
+
|
|
23
|
+
输入:s = "Python"
|
|
24
|
+
输出:"nohtyP"
|
|
25
|
+
|
|
26
|
+
输入:s = ""
|
|
27
|
+
输出:""
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
|
|
32
|
+
def TEST_DO_NOT_CHANGE(s):
|
|
33
|
+
rlt = None
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
def reverse(text):
|
|
37
|
+
if len(text) < 2:
|
|
38
|
+
return text
|
|
39
|
+
middle = len(text) // 2
|
|
40
|
+
return reverse(text[middle:]) + reverse(text[:middle])
|
|
41
|
+
|
|
42
|
+
rlt = reverse(s)
|
|
43
|
+
|
|
44
|
+
##########end上面可以改动
|
|
45
|
+
return rlt
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
###########下面可以修改
|
|
49
|
+
print(TEST_DO_NOT_CHANGE("hello"))
|
|
50
|
+
print(TEST_DO_NOT_CHANGE("Python"))
|
|
51
|
+
print(TEST_DO_NOT_CHANGE(""))
|
|
52
|
+
# 题号:hwc238
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·二分查找考点)
|
|
15
|
+
给定一个升序排列(从小到大)的整数列表 nums 和一个目标值 target,
|
|
16
|
+
用二分查找在 nums 中寻找 target。
|
|
17
|
+
若找到,返回 target 在 nums 中的下标(从 0 开始);
|
|
18
|
+
若不存在,返回 -1。
|
|
19
|
+
要求时间复杂度 O(log n)——即每次比较都把搜索范围缩小一半(二分),不能从头到尾逐个找。
|
|
20
|
+
若 nums 含有重复值,返回该 target 的任意一个下标即可。
|
|
21
|
+
|
|
22
|
+
示例:
|
|
23
|
+
输入:nums = [1, 3, 5, 7, 9, 11, 13], target = 7
|
|
24
|
+
输出:3
|
|
25
|
+
|
|
26
|
+
输入:nums = [1, 3, 5, 7, 9, 11, 13], target = 8
|
|
27
|
+
输出:-1
|
|
28
|
+
|
|
29
|
+
输入:nums = [], target = 0
|
|
30
|
+
输出:-1
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
|
|
35
|
+
def TEST_DO_NOT_CHANGE(nums, target):
|
|
36
|
+
rlt = None
|
|
37
|
+
##########start下面可以改动
|
|
38
|
+
|
|
39
|
+
rlt = -1
|
|
40
|
+
left, right = 0, len(nums) - 1
|
|
41
|
+
while left <= right:
|
|
42
|
+
middle = (left + right) // 2
|
|
43
|
+
if nums[middle] == target:
|
|
44
|
+
rlt = middle
|
|
45
|
+
break
|
|
46
|
+
if nums[middle] < target:
|
|
47
|
+
left = middle + 1
|
|
48
|
+
else:
|
|
49
|
+
right = middle - 1
|
|
50
|
+
|
|
51
|
+
##########end上面可以改动
|
|
52
|
+
return rlt
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
###########下面可以修改
|
|
56
|
+
print(TEST_DO_NOT_CHANGE([1, 3, 5, 7, 9, 11, 13], 7))
|
|
57
|
+
print(TEST_DO_NOT_CHANGE([1, 3, 5, 7, 9, 11, 13], 8))
|
|
58
|
+
print(TEST_DO_NOT_CHANGE([1], 1))
|
|
59
|
+
print(TEST_DO_NOT_CHANGE([], 0))
|
|
60
|
+
# 题号:hwc239
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·枚举考点)
|
|
15
|
+
中国古代数学家张丘建在《算经》中提出了著名的"百钱买百鸡"问题:
|
|
16
|
+
鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一。
|
|
17
|
+
百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?
|
|
18
|
+
即:用 100 文钱买 100 只鸡,公鸡每只 5 文、母鸡每只 3 文、小鸡 3 只 1 文,
|
|
19
|
+
公鸡、母鸡、小鸡各买多少只?把所有解存到一个列表返回(每个解是 (公,母,小) 三元组)。
|
|
20
|
+
返回列表按公鸡数量从小到大排序。
|
|
21
|
+
|
|
22
|
+
示例:
|
|
23
|
+
输出:[ (0, 25, 75), (4, 18, 78), (8, 11, 81), (12, 4, 84) ]
|
|
24
|
+
'''
|
|
25
|
+
|
|
26
|
+
# 参考答案
|
|
27
|
+
|
|
28
|
+
def TEST_DO_NOT_CHANGE():
|
|
29
|
+
lst_rlt = None
|
|
30
|
+
##########start下面可以改动
|
|
31
|
+
|
|
32
|
+
lst_rlt = []
|
|
33
|
+
for roosters in range(21):
|
|
34
|
+
for hens in range(34):
|
|
35
|
+
chicks = 100 - roosters - hens
|
|
36
|
+
if 15 * roosters + 9 * hens + chicks == 300:
|
|
37
|
+
lst_rlt.append((roosters, hens, chicks))
|
|
38
|
+
|
|
39
|
+
##########end上面可以改动
|
|
40
|
+
return lst_rlt
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
###########下面可以修改
|
|
44
|
+
print(TEST_DO_NOT_CHANGE())
|
|
45
|
+
# 题号:hwc240
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·简单应用题·枚举考点)
|
|
15
|
+
鸡兔同笼问题:已知笼中共有头 h 个,脚 f 只。
|
|
16
|
+
鸡有 2 只脚,兔有 4 只脚。问鸡和兔各有多少只?
|
|
17
|
+
若方程有唯一非负整数解,返回 (鸡数, 兔数);若无非负整数解,返回 (0, 0)。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
输入:h = 35, f = 94
|
|
21
|
+
输出:(23, 12) # 23 只鸡 + 12 只兔 = 35 头,46+48 = 94 脚
|
|
22
|
+
|
|
23
|
+
输入:h = 10, f = 30
|
|
24
|
+
输出:(5, 5)
|
|
25
|
+
|
|
26
|
+
输入:h = 10, f = 25 # 奇数只脚,无解
|
|
27
|
+
输出:(0, 0)
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
|
|
32
|
+
def TEST_DO_NOT_CHANGE(h, f):
|
|
33
|
+
rlt = None
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
rabbits, remainder = divmod(f - 2 * h, 2)
|
|
37
|
+
rlt = (h - rabbits, rabbits) if not remainder and 0 <= rabbits <= h else (0, 0)
|
|
38
|
+
|
|
39
|
+
##########end上面可以改动
|
|
40
|
+
return rlt
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
###########下面可以修改
|
|
44
|
+
print(TEST_DO_NOT_CHANGE(35, 94))
|
|
45
|
+
print(TEST_DO_NOT_CHANGE(10, 30))
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(10, 25))
|
|
47
|
+
print(TEST_DO_NOT_CHANGE(1, 3))
|
|
48
|
+
# 题号:hwc241
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·枚举+字符串考点)
|
|
15
|
+
完全平方数是指一个整数可以写成某个整数的平方,例如 1, 4, 9, 16, 25...
|
|
16
|
+
给定一个正整数 n,请找出所有小于等于 n 的“各位数字之和为偶数”的完全平方数,
|
|
17
|
+
按从小到大顺序存入列表返回。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
输入:n = 30
|
|
21
|
+
输出:[4] # 4 的各位和为 4(偶数);16 和 25 的各位和均为 7(奇数),舍去
|
|
22
|
+
|
|
23
|
+
输入:n = 100
|
|
24
|
+
输出:[4, 64]
|
|
25
|
+
# 4 和 64 的各位数字之和分别为 4 和 10,均为偶数。
|
|
26
|
+
'''
|
|
27
|
+
|
|
28
|
+
# 参考答案
|
|
29
|
+
|
|
30
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
31
|
+
lst_rlt = None
|
|
32
|
+
##########start下面可以改动
|
|
33
|
+
|
|
34
|
+
from math import isqrt
|
|
35
|
+
|
|
36
|
+
lst_rlt = []
|
|
37
|
+
for root in range(1, isqrt(n) + 1):
|
|
38
|
+
square = root * root
|
|
39
|
+
if sum(map(int, str(square))) % 2 == 0:
|
|
40
|
+
lst_rlt.append(square)
|
|
41
|
+
|
|
42
|
+
##########end上面可以改动
|
|
43
|
+
return lst_rlt
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
###########下面可以修改
|
|
47
|
+
print(TEST_DO_NOT_CHANGE(30))
|
|
48
|
+
print(TEST_DO_NOT_CHANGE(100))
|
|
49
|
+
print(TEST_DO_NOT_CHANGE(50))
|
|
50
|
+
# 题号:hwc242
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定一个正整数,返回它在 Excel 表中相对应的列名称。
|
|
16
|
+
|
|
17
|
+
例如,
|
|
18
|
+
1 -> A
|
|
19
|
+
2 -> B
|
|
20
|
+
3 -> C
|
|
21
|
+
...
|
|
22
|
+
26 -> Z
|
|
23
|
+
27 -> AA
|
|
24
|
+
28 -> AB
|
|
25
|
+
...
|
|
26
|
+
|
|
27
|
+
示例 1:
|
|
28
|
+
输入: 1
|
|
29
|
+
输出: "A"
|
|
30
|
+
|
|
31
|
+
示例2:
|
|
32
|
+
输入: 28
|
|
33
|
+
输出: "AB"
|
|
34
|
+
|
|
35
|
+
示例3:
|
|
36
|
+
输入: 701
|
|
37
|
+
输出: "ZY"
|
|
38
|
+
'''
|
|
39
|
+
|
|
40
|
+
# 参考答案
|
|
41
|
+
|
|
42
|
+
def TEST_DO_NOT_CHANGE(columnNumber):
|
|
43
|
+
print(columnNumber)
|
|
44
|
+
rlt = None
|
|
45
|
+
##########start下面可以改动
|
|
46
|
+
|
|
47
|
+
letters = []
|
|
48
|
+
while columnNumber:
|
|
49
|
+
columnNumber, digit = divmod(columnNumber - 1, 26)
|
|
50
|
+
letters.append(chr(ord("A") + digit))
|
|
51
|
+
rlt = "".join(reversed(letters))
|
|
52
|
+
|
|
53
|
+
##########end上面可以改动
|
|
54
|
+
return rlt
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
###########下面可以修改
|
|
58
|
+
print(TEST_DO_NOT_CHANGE(1))
|
|
59
|
+
print(TEST_DO_NOT_CHANGE(28))
|
|
60
|
+
print(TEST_DO_NOT_CHANGE(701))
|
|
61
|
+
# 题号:hwc243
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:校验密码强度
|
|
14
|
+
|
|
15
|
+
编写函数 TEST_DO_NOT_CHANGE(password),用于校验用户输入的密码强度。密码强度的规则如下:
|
|
16
|
+
|
|
17
|
+
密码长度必须至少为8个字符。
|
|
18
|
+
密码必须包含至少一个大写字母、一个小写字母、一个数字和一个特殊字符(例如:!@#$%^&*)。
|
|
19
|
+
密码不能包含连续的3个字符,如 "123" 或 "abc"。
|
|
20
|
+
编写一个函数 check_password_strength(password),接受一个字符串 password 作为参数,返回一个布尔值,表示密码是否符合以上规则。
|
|
21
|
+
|
|
22
|
+
例如,以下是一些示例:
|
|
23
|
+
|
|
24
|
+
"Abc123!@" 是一个不符合规则的密码,应该返回 False
|
|
25
|
+
"password1" 不符合规则,因为没有特殊字符,应该返回 False。
|
|
26
|
+
"Abcde12345" 不符合规则,因为包含连续的数字,应该返回 False。
|
|
27
|
+
'''
|
|
28
|
+
|
|
29
|
+
# 参考答案
|
|
30
|
+
import re
|
|
31
|
+
|
|
32
|
+
def TEST_DO_NOT_CHANGE(password):
|
|
33
|
+
result=None
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
from string import ascii_lowercase, digits, punctuation
|
|
37
|
+
|
|
38
|
+
# 连续序列按不区分大小写的 ASCII 字母与数字检查,含顺序和逆序。
|
|
39
|
+
result = bool(
|
|
40
|
+
len(password) >= 8
|
|
41
|
+
and re.search(r"[A-Z]", password)
|
|
42
|
+
and re.search(r"[a-z]", password)
|
|
43
|
+
and re.search(r"[0-9]", password)
|
|
44
|
+
and any(char in punctuation for char in password)
|
|
45
|
+
)
|
|
46
|
+
lower = password.lower()
|
|
47
|
+
for alphabet in (ascii_lowercase, digits):
|
|
48
|
+
for i in range(len(alphabet) - 2):
|
|
49
|
+
run = alphabet[i:i + 3]
|
|
50
|
+
if run in lower or run[::-1] in lower:
|
|
51
|
+
result = False
|
|
52
|
+
|
|
53
|
+
##########end上面可以改动
|
|
54
|
+
return result
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
###########下面可以修改
|
|
58
|
+
print(TEST_DO_NOT_CHANGE("Abc123!@")) # False
|
|
59
|
+
print(TEST_DO_NOT_CHANGE("password1")) # False
|
|
60
|
+
print(TEST_DO_NOT_CHANGE("Abcde12345")) # False
|
|
61
|
+
# 题号:hwc244
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:定义一个函数,实现输入一句话,单词之间使用空格隔开,统计出其中各单词的词频数,
|
|
15
|
+
并以keyword:count的格式存在一个dict中,返回这个dict。
|
|
16
|
+
注意 jkl; 不是一个单词,jkl 是一个单词,要把 @+;:?! 非字符符号去掉
|
|
17
|
+
即输入:“abc fjf jkl+ abc abc jkl;” 结果是 {"abc":3,"fjf":1,"jkl":2}
|
|
18
|
+
|
|
19
|
+
注意
|
|
20
|
+
1 `strip(chars)` 只能移除字符串首尾属于 chars 的字符,不能移除中间标点;若要去除整句中的标点,应使用 `translate`、正则表达式或逐字符过滤。
|
|
21
|
+
str_1 = 'jkl+'
|
|
22
|
+
str_1= str_1.strip(' @+;:?!')
|
|
23
|
+
|
|
24
|
+
2字符串中的split() 可以分割字符串
|
|
25
|
+
str_1 = 'hello world'
|
|
26
|
+
lst_str= str_1.split(' ')
|
|
27
|
+
'''
|
|
28
|
+
|
|
29
|
+
# 参考答案
|
|
30
|
+
|
|
31
|
+
def TEST_DO_NOT_CHANGE(str_line):
|
|
32
|
+
word_dict = {}
|
|
33
|
+
##########start下面可以改动
|
|
34
|
+
|
|
35
|
+
stripped = str_line.translate(str.maketrans("", "", "@+;:?!"))
|
|
36
|
+
for word in stripped.split():
|
|
37
|
+
word_dict[word] = word_dict.get(word, 0) + 1
|
|
38
|
+
|
|
39
|
+
##########end上面可以改动
|
|
40
|
+
return word_dict
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
###########下面可以修改
|
|
45
|
+
str_line = "abc! fjf jkl+ abc abc jkl;"
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(str_line))
|
|
47
|
+
# 题号:hwc245
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给你一个整数数组 citations ,其中 citations[i] 表示研究者的第 i 篇论文被引用的次数。计算并返回该研究者的 h指数。
|
|
16
|
+
|
|
17
|
+
定义:h 代表“高引用次数”。一名科研人员的 h 指数这样算:他有 n 篇论文,如果其中 至少有 h 篇每篇被引用了至少 h 次,那么这个 h 就成立;h 指数就是满足条件的最大的那个 h。
|
|
18
|
+
(例如有 3 篇论文各被引用了至少 3 次,但没有 4 篇各被引用至少 4 次,那么 h 指数就是 3。)
|
|
19
|
+
|
|
20
|
+
示例 1:
|
|
21
|
+
|
|
22
|
+
输入:citations = [3,0,6,1,5]
|
|
23
|
+
输出:3
|
|
24
|
+
解释:给定数组表示研究者总共有 5 篇论文,每篇论文相应的被引用了 3, 0, 6, 1, 5 次。
|
|
25
|
+
由于研究者有 3 篇论文每篇 至少 被引用了 3 次,其余两篇论文每篇被引用 不多于 3 次,所以她的 h 指数是 3。
|
|
26
|
+
|
|
27
|
+
示例 2:
|
|
28
|
+
|
|
29
|
+
输入:citations = [1,3,1]
|
|
30
|
+
输出:1
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
35
|
+
rlt = None
|
|
36
|
+
##########start下面可以改动
|
|
37
|
+
|
|
38
|
+
rlt = 0
|
|
39
|
+
for count, citations in enumerate(sorted(nums, reverse=True), 1):
|
|
40
|
+
if citations < count:
|
|
41
|
+
break
|
|
42
|
+
rlt = count
|
|
43
|
+
|
|
44
|
+
##########end上面可以改动
|
|
45
|
+
return rlt
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
###########下面可以修改
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([3,0,6,1,5]))
|
|
51
|
+
print(TEST_DO_NOT_CHANGE([1,3,1]))
|
|
52
|
+
# 题号:hwc246
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定一个正整数n ,输出外观数列的第 n 项。
|
|
16
|
+
「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。
|
|
17
|
+
|
|
18
|
+
你可以将其视作是由递归公式定义的数字字符串序列:
|
|
19
|
+
1. countAndSay(1) = "1"
|
|
20
|
+
2. countAndSay(n) 是对 countAndSay(n-1) 的描述,然后转换成另一个数字字符串。
|
|
21
|
+
前五项如下:
|
|
22
|
+
|
|
23
|
+
1
|
|
24
|
+
11
|
|
25
|
+
21
|
|
26
|
+
1211
|
|
27
|
+
111221
|
|
28
|
+
|
|
29
|
+
第一项是数字 1
|
|
30
|
+
描述前一项,这个数是 1 即 “ 一 个 1 ”,记作 "11"
|
|
31
|
+
描述前一项,这个数是 11 即 “ 二 个 1 ” ,记作 "21"
|
|
32
|
+
描述前一项,这个数是 21 即 “ 一 个 2 + 一 个 1 ” ,记作 "1211"
|
|
33
|
+
描述前一项,这个数是 1211 即 “ 一 个 1 + 一 个 2 + 二 个 1 ” ,记作 "111221"
|
|
34
|
+
|
|
35
|
+
示例 1:
|
|
36
|
+
|
|
37
|
+
输入: n = 1
|
|
38
|
+
输出: "1"
|
|
39
|
+
解释: 这是一个基本样例。
|
|
40
|
+
|
|
41
|
+
示例 2:
|
|
42
|
+
|
|
43
|
+
输入: n = 4
|
|
44
|
+
输出: "1211"
|
|
45
|
+
解释: countAndSay(1) = "1"
|
|
46
|
+
countAndSay(2) = 读 "1" = 一 个 1 = "11"
|
|
47
|
+
countAndSay(3) = 读 "11" = 二 个 1 = "21"
|
|
48
|
+
countAndSay(4) = 读 "21" = 一 个 2 + 一 个 1 = "12" + "11" = "1211"
|
|
49
|
+
|
|
50
|
+
示例 3:
|
|
51
|
+
|
|
52
|
+
输入: n = 8
|
|
53
|
+
输出: "1113213211"
|
|
54
|
+
'''
|
|
55
|
+
|
|
56
|
+
# 参考答案
|
|
57
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
58
|
+
res = ''
|
|
59
|
+
##########start下面可以改动
|
|
60
|
+
|
|
61
|
+
from itertools import groupby
|
|
62
|
+
|
|
63
|
+
res = "1"
|
|
64
|
+
for _ in range(n - 1):
|
|
65
|
+
res = "".join(f"{sum(1 for _ in group)}{digit}" for digit, group in groupby(res))
|
|
66
|
+
|
|
67
|
+
##########end上面可以改动
|
|
68
|
+
return res
|
|
69
|
+
|
|
70
|
+
if __name__ == '__main__':
|
|
71
|
+
###########下面可以修改
|
|
72
|
+
print(TEST_DO_NOT_CHANGE(1))
|
|
73
|
+
print(TEST_DO_NOT_CHANGE(4))
|
|
74
|
+
print(TEST_DO_NOT_CHANGE(8))
|
|
75
|
+
|
|
76
|
+
# 题号:hwc247
|