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,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
求数字 0—7 在数字不重复使用的条件下所能组成的 n 位奇数个数。
|
|
16
|
+
程序分析:
|
|
17
|
+
组成 1 位数是 4 个;后续各位不能重复使用已经选过的数字,且最高位不能为 0。
|
|
18
|
+
输入是 n n为几位数
|
|
19
|
+
输出是 奇数个数
|
|
20
|
+
如 输入 n=4
|
|
21
|
+
输出的 rlt_sum=7*8*8*4
|
|
22
|
+
'''
|
|
23
|
+
|
|
24
|
+
# 参考答案
|
|
25
|
+
|
|
26
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
27
|
+
rlt_sum = None
|
|
28
|
+
##########start下面可以改动
|
|
29
|
+
|
|
30
|
+
from math import perm
|
|
31
|
+
|
|
32
|
+
# 按题干的“不重复、首位非零”计算。n=4 时为 4×6×6×5=720。
|
|
33
|
+
if n == 1:
|
|
34
|
+
rlt_sum = 4
|
|
35
|
+
elif 2 <= n <= 8:
|
|
36
|
+
rlt_sum = 4 * 6 * perm(6, n - 2)
|
|
37
|
+
else:
|
|
38
|
+
rlt_sum = 0
|
|
39
|
+
|
|
40
|
+
##########end上面可以改动
|
|
41
|
+
return rlt_sum
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
###########下面可以修改
|
|
46
|
+
print (TEST_DO_NOT_CHANGE(4))
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
查找字符串 str_2 在 str_1 中第一次出现的位置。下标从 0 开始,
|
|
16
|
+
返回 (start, end):start 是匹配段第一个字符的下标,end 是匹配段最后一个字符的下标(包含该字符);
|
|
17
|
+
如果不存在返回 (-1, -1)。
|
|
18
|
+
例如:在字符串 abcdefg 中查找 cde,匹配段是下标 2、3、4 的字符,返回 (2, 4)。
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
# 参考答案
|
|
22
|
+
|
|
23
|
+
def TEST_DO_NOT_CHANGE(str_1,str_2):
|
|
24
|
+
i_start = -1
|
|
25
|
+
i_end = -1
|
|
26
|
+
##########start下面可以改动
|
|
27
|
+
|
|
28
|
+
i_start = str_1.find(str_2)
|
|
29
|
+
if i_start != -1:
|
|
30
|
+
i_end = i_start + len(str_2) - 1
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return i_start,i_end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
###########下面可以修改
|
|
38
|
+
print (TEST_DO_NOT_CHANGE('abcdefg','cde'))
|
|
@@ -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
|
+
0, 1, 2, ..., n 这 n+1 个连续整数中,有一个数缺席了。数组 nums 里装着剩下的 n 个数(顺序打乱、互不重复),
|
|
16
|
+
请找出缺席的那个数。
|
|
17
|
+
|
|
18
|
+
进阶(可选):
|
|
19
|
+
|
|
20
|
+
你能否只把数组遍历一遍、并且几乎不使用额外空间(不新建与数组等长的容器)解决此问题?
|
|
21
|
+
|
|
22
|
+
示例 1:
|
|
23
|
+
|
|
24
|
+
输入:nums = [3,0,1]
|
|
25
|
+
输出:2
|
|
26
|
+
解释:n = 3,因为有 3 个数字,所以所有的数字都在范围 [0,3] 内。2 是丢失的数字,因为它没有出现在 nums 中。
|
|
27
|
+
示例 2:
|
|
28
|
+
|
|
29
|
+
输入:nums = [0,1]
|
|
30
|
+
输出:2
|
|
31
|
+
解释:n = 2,因为有 2 个数字,所以所有的数字都在范围 [0,2] 内。2 是丢失的数字,因为它没有出现在 nums 中。
|
|
32
|
+
示例 3:
|
|
33
|
+
|
|
34
|
+
输入:nums = [9,6,4,2,3,5,7,0,1]
|
|
35
|
+
输出:8
|
|
36
|
+
解释:n = 9,因为有 9 个数字,所以所有的数字都在范围 [0,9] 内。8 是丢失的数字,因为它没有出现在 nums 中。
|
|
37
|
+
示例 4:
|
|
38
|
+
|
|
39
|
+
输入:nums = [0]
|
|
40
|
+
输出:1
|
|
41
|
+
解释:n = 1,因为有 1 个数字,所以所有的数字都在范围 [0,1] 内。1 是丢失的数字,因为它没有出现在 nums 中。
|
|
42
|
+
'''
|
|
43
|
+
|
|
44
|
+
# 参考答案
|
|
45
|
+
|
|
46
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
47
|
+
rlt=None
|
|
48
|
+
##########start下面可以改动
|
|
49
|
+
|
|
50
|
+
n = len(nums)
|
|
51
|
+
rlt = n * (n + 1) // 2 - sum(nums)
|
|
52
|
+
|
|
53
|
+
##########end上面可以改动
|
|
54
|
+
return rlt
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
###########下面可以修改
|
|
60
|
+
print(TEST_DO_NOT_CHANGE([9,6,4,2,3,5,7,0,1]))
|
|
61
|
+
print(TEST_DO_NOT_CHANGE([0,1]))
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:计算斐波那契数列
|
|
15
|
+
|
|
16
|
+
编写一个 Python 程序,计算并输出斐波那契数列的前 n 个数字。
|
|
17
|
+
|
|
18
|
+
斐波那契数列的定义如下:
|
|
19
|
+
|
|
20
|
+
第一个和第二个数字都是 1。
|
|
21
|
+
从第三个数字开始,每个数字都是前两个数字之和。
|
|
22
|
+
例如,前几个斐波那契数字是:1, 1, 2, 3, 5, 8, 13, 21, ...
|
|
23
|
+
|
|
24
|
+
要求:返回一个列表,包含斐波那契数列的前 n 项。
|
|
25
|
+
'''
|
|
26
|
+
|
|
27
|
+
# 参考答案
|
|
28
|
+
|
|
29
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
30
|
+
fibs = []
|
|
31
|
+
##########start下面可以改动
|
|
32
|
+
|
|
33
|
+
first, second = 1, 1
|
|
34
|
+
for _ in range(n):
|
|
35
|
+
fibs.append(first)
|
|
36
|
+
first, second = second, first + second
|
|
37
|
+
|
|
38
|
+
##########end上面可以改动
|
|
39
|
+
return fibs
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
###########下面可以修改
|
|
43
|
+
print(TEST_DO_NOT_CHANGE(20))
|
|
44
|
+
print(TEST_DO_NOT_CHANGE(15))
|
|
45
|
+
print(TEST_DO_NOT_CHANGE(10))
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符:
|
|
16
|
+
|
|
17
|
+
'A' : Absent,缺勤
|
|
18
|
+
'L' : Late,迟到
|
|
19
|
+
'P' : Present,到场
|
|
20
|
+
如果一个学生的出勤记录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。
|
|
21
|
+
|
|
22
|
+
你需要根据这个学生的出勤记录判断他是否会被奖赏。
|
|
23
|
+
|
|
24
|
+
示例 1:
|
|
25
|
+
|
|
26
|
+
输入: "PPALLP"
|
|
27
|
+
输出: True
|
|
28
|
+
示例 2:
|
|
29
|
+
|
|
30
|
+
输入: "PPALLL"
|
|
31
|
+
输出: False
|
|
32
|
+
'''
|
|
33
|
+
|
|
34
|
+
# 参考答案
|
|
35
|
+
|
|
36
|
+
def TEST_DO_NOT_CHANGE(str_1):
|
|
37
|
+
print(str_1)
|
|
38
|
+
rlt = None
|
|
39
|
+
##########start下面可以改动
|
|
40
|
+
|
|
41
|
+
rlt = str_1.count("A") <= 1 and "LLL" not in str_1
|
|
42
|
+
|
|
43
|
+
##########end上面可以改动
|
|
44
|
+
return rlt
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
###########下面可以修改
|
|
48
|
+
print(TEST_DO_NOT_CHANGE("PPALLP"))
|
|
49
|
+
print(TEST_DO_NOT_CHANGE("PPALLL")) # 应为 False
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:查找素数
|
|
14
|
+
|
|
15
|
+
编写一个 Python 程序,接受用户输入的正整数 n,然后查找并输出从 2 到 n 之间的所有素数。
|
|
16
|
+
|
|
17
|
+
素数是指只能被 1 和自身整除的正整数。例如,2、3、5、7、11 等都是素数。
|
|
18
|
+
|
|
19
|
+
编写一个函数 TEST_DO_NOT_CHANGE(n),它接受一个正整数 n 作为参数,返回一个包含从 2 到 n 之间的所有素数的列表。
|
|
20
|
+
|
|
21
|
+
例如,如果用户输入 n = 20,程序应该输出 [2, 3, 5, 7, 11, 13, 17, 19]。
|
|
22
|
+
'''
|
|
23
|
+
|
|
24
|
+
# 参考答案
|
|
25
|
+
|
|
26
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
27
|
+
primes = []
|
|
28
|
+
##########start下面可以改动
|
|
29
|
+
|
|
30
|
+
from math import isqrt
|
|
31
|
+
|
|
32
|
+
for value in range(2, n + 1):
|
|
33
|
+
if all(value % divisor != 0 for divisor in range(2, isqrt(value) + 1)):
|
|
34
|
+
primes.append(value)
|
|
35
|
+
|
|
36
|
+
##########end上面可以改动
|
|
37
|
+
return primes
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
###########下面可以修改
|
|
41
|
+
print(TEST_DO_NOT_CHANGE(20))
|
|
42
|
+
print(TEST_DO_NOT_CHANGE(30))
|
|
43
|
+
print(TEST_DO_NOT_CHANGE(40))
|
|
@@ -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
|
+
给定一个整数数组 nums和一个整数目标值 target,请你在该数组中找出和为目标值的那两个整数,并返回它们的数组下标。
|
|
16
|
+
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
|
|
17
|
+
你可以按任意顺序返回答案。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
输入:nums = [2,7,11,15], target = 9
|
|
21
|
+
输出:[0,1]
|
|
22
|
+
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。
|
|
23
|
+
'''
|
|
24
|
+
|
|
25
|
+
# 参考答案
|
|
26
|
+
|
|
27
|
+
def TEST_DO_NOT_CHANGE( nums, target):
|
|
28
|
+
print(nums, target)
|
|
29
|
+
lst_rlt = []
|
|
30
|
+
##########start下面可以改动
|
|
31
|
+
|
|
32
|
+
seen = {}
|
|
33
|
+
for index, value in enumerate(nums):
|
|
34
|
+
complement = target - value
|
|
35
|
+
if complement in seen:
|
|
36
|
+
lst_rlt = [seen[complement], index]
|
|
37
|
+
break
|
|
38
|
+
seen[value] = index
|
|
39
|
+
|
|
40
|
+
##########end上面可以改动
|
|
41
|
+
return lst_rlt
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
###########下面可以修改
|
|
45
|
+
print(TEST_DO_NOT_CHANGE([2,7,11,15],9))
|
|
46
|
+
print(TEST_DO_NOT_CHANGE([3,2,4],6))
|
|
47
|
+
print(TEST_DO_NOT_CHANGE([3,3],6))
|
|
@@ -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
|
+
给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序,
|
|
16
|
+
返回移动后的新列表(本题不要求修改原数组)。
|
|
17
|
+
注:本题为基础版;进阶版(直接在原数组上修改)见 hwc225。
|
|
18
|
+
|
|
19
|
+
示例 1:
|
|
20
|
+
|
|
21
|
+
输入: [0,1,0,3,12]
|
|
22
|
+
输出: [1,3,12,0,0]
|
|
23
|
+
|
|
24
|
+
示例 2:
|
|
25
|
+
|
|
26
|
+
输入: [0]
|
|
27
|
+
输出: [0]
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
from typing import List
|
|
32
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
33
|
+
res = []
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
res = [value for value in nums if value != 0]
|
|
37
|
+
res.extend([0] * (len(nums) - len(res)))
|
|
38
|
+
|
|
39
|
+
##########end上面可以改动
|
|
40
|
+
return res
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
###########下面可以修改
|
|
45
|
+
|
|
46
|
+
print(TEST_DO_NOT_CHANGE([0,1,0,3,12]))
|
|
47
|
+
print(TEST_DO_NOT_CHANGE([0]))
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给你一个有序数组 nums,请你原地删除重复出现的元素,使每个元素只出现一次,并返回删除后数组的新长度。
|
|
16
|
+
不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。
|
|
17
|
+
|
|
18
|
+
示例 1:
|
|
19
|
+
|
|
20
|
+
输入: nums = [1,1,2]
|
|
21
|
+
输出: 2;修改后的 nums 前两个元素为 [1,2]
|
|
22
|
+
解释: 函数应该返回新的长度 2 ,并且原数组 nums 的前两个元素被修改为 1, 2 。不需要考虑数组中超出新长度后面的元素。
|
|
23
|
+
|
|
24
|
+
示例 2:
|
|
25
|
+
|
|
26
|
+
输入: nums = [0,0,1,1,1,2,2,3,3,4]
|
|
27
|
+
输出: 5;修改后的 nums 前五个元素为 [0,1,2,3,4]
|
|
28
|
+
解释: 函数应该返回新的长度 5 , 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4 。不需要考虑数组中超出新长度后面的元素。
|
|
29
|
+
'''
|
|
30
|
+
|
|
31
|
+
# 参考答案
|
|
32
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
33
|
+
num = 0
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
for value in nums:
|
|
37
|
+
if num == 0 or value != nums[num - 1]:
|
|
38
|
+
nums[num] = value
|
|
39
|
+
num += 1
|
|
40
|
+
|
|
41
|
+
##########end上面可以改动
|
|
42
|
+
return num
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
###########下面可以修改
|
|
47
|
+
print(TEST_DO_NOT_CHANGE([1,1,2]))
|
|
48
|
+
print(TEST_DO_NOT_CHANGE([0,0,1,1,1,2,2,3,3,4]))
|
|
@@ -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
|
+
有一个字符串sequence,如果字符串 word连续重复k次形成的字符串是sequence的一个子字符串,那么单词word 的 重复值为 k 。
|
|
16
|
+
其中单词 word的 最大重复值是单词word在sequence中最大的重复值。如果word不是sequence的子串,那么重复值k为 0 。
|
|
17
|
+
|
|
18
|
+
现在给你一个字符串 sequence和 word,请你返回 最大重复值k 。
|
|
19
|
+
|
|
20
|
+
示例 1:
|
|
21
|
+
|
|
22
|
+
输入:sequence = "ababc", word = "ab"
|
|
23
|
+
输出:2
|
|
24
|
+
解释:"abab" 是 "ababc" 的子字符串。
|
|
25
|
+
示例 2:
|
|
26
|
+
|
|
27
|
+
输入:sequence = "ababc", word = "ba"
|
|
28
|
+
输出:1
|
|
29
|
+
解释:"ba" 是 "ababc" 的子字符串,但 "baba" 不是 "ababc" 的子字符串。
|
|
30
|
+
示例 3:
|
|
31
|
+
|
|
32
|
+
输入:sequence = "ababc", word = "ac"
|
|
33
|
+
输出:0
|
|
34
|
+
解释:"ac" 不是 "ababc" 的子字符串。
|
|
35
|
+
'''
|
|
36
|
+
|
|
37
|
+
# 参考答案
|
|
38
|
+
def TEST_DO_NOT_CHANGE(sequence,word):
|
|
39
|
+
print(sequence,word)
|
|
40
|
+
rlt = None
|
|
41
|
+
##########start下面可以改动
|
|
42
|
+
|
|
43
|
+
rlt = 0
|
|
44
|
+
if word:
|
|
45
|
+
low, high = 0, len(sequence) // len(word)
|
|
46
|
+
while low < high:
|
|
47
|
+
middle = (low + high + 1) // 2
|
|
48
|
+
if word * middle in sequence:
|
|
49
|
+
low = middle
|
|
50
|
+
else:
|
|
51
|
+
high = middle - 1
|
|
52
|
+
rlt = low
|
|
53
|
+
|
|
54
|
+
##########end上面可以改动
|
|
55
|
+
return rlt
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
###########下面可以修改
|
|
59
|
+
sequence = "ababc"
|
|
60
|
+
word = "ab"
|
|
61
|
+
print(TEST_DO_NOT_CHANGE(sequence,word))
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度,和新的nums。
|
|
16
|
+
|
|
17
|
+
不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。
|
|
18
|
+
元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。
|
|
19
|
+
|
|
20
|
+
示例 1:
|
|
21
|
+
|
|
22
|
+
输入: nums = [3,2,2,3], val = 3
|
|
23
|
+
输出: 2, nums = [2,2]
|
|
24
|
+
解释: 函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。你不需要考虑数组中超出新长度后面的元素。例如,函数返回的新长度为 2 ,而 nums = [2,2,3,3] 或 nums = [2,2,0,0],也会被视作正确答案。
|
|
25
|
+
|
|
26
|
+
示例 2:
|
|
27
|
+
|
|
28
|
+
输入: nums = [0,1,2,2,3,0,4,2], val = 2
|
|
29
|
+
输出: 5, nums = [0,1,4,0,3]
|
|
30
|
+
解释: 函数应该返回新的长度 5, 并且 nums 中的前五个元素为 0, 1, 4, 0, 3。注意这五个元素可为任意顺序。你不需要考虑数组中超出新长度后面的元素。
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
|
|
35
|
+
from typing import List
|
|
36
|
+
def TEST_DO_NOT_CHANGE(nums, val):
|
|
37
|
+
num = 0
|
|
38
|
+
res = []
|
|
39
|
+
##########start下面可以改动
|
|
40
|
+
|
|
41
|
+
for value in nums:
|
|
42
|
+
if value != val:
|
|
43
|
+
nums[num] = value
|
|
44
|
+
num += 1
|
|
45
|
+
while len(nums) > num:
|
|
46
|
+
nums.pop()
|
|
47
|
+
res = nums
|
|
48
|
+
|
|
49
|
+
##########end上面可以改动
|
|
50
|
+
return num, res
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
###########下面可以修改
|
|
55
|
+
print(TEST_DO_NOT_CHANGE([3,2,2,3],3))
|
|
56
|
+
print(TEST_DO_NOT_CHANGE([0,1,2,2,3,0,4,2],2))
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 i 和 j 的差的 绝对值 至多为 k。
|
|
16
|
+
|
|
17
|
+
示例 1:
|
|
18
|
+
|
|
19
|
+
输入: nums = [1,2,3,1], k = 3
|
|
20
|
+
输出: True
|
|
21
|
+
|
|
22
|
+
示例 2:
|
|
23
|
+
|
|
24
|
+
输入: nums = [1,0,1,1], k = 1
|
|
25
|
+
输出: True
|
|
26
|
+
|
|
27
|
+
示例 3:
|
|
28
|
+
|
|
29
|
+
输入: nums = [1,2,3,1,2,3], k = 2
|
|
30
|
+
输出: False
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
def TEST_DO_NOT_CHANGE(nums, k):
|
|
35
|
+
res=False
|
|
36
|
+
##########start下面可以改动
|
|
37
|
+
|
|
38
|
+
last_index = {}
|
|
39
|
+
for index, value in enumerate(nums):
|
|
40
|
+
if value in last_index and index - last_index[value] <= k:
|
|
41
|
+
res = True
|
|
42
|
+
break
|
|
43
|
+
last_index[value] = index
|
|
44
|
+
|
|
45
|
+
##########end上面可以改动
|
|
46
|
+
return res
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
###########下面可以修改
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([1,2,3,1],3))
|
|
51
|
+
print(TEST_DO_NOT_CHANGE([1,0,1,1],1))
|
|
52
|
+
print(TEST_DO_NOT_CHANGE([1,2,3,1,2,3],2))
|
|
53
|
+
# 题号:hwc206
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
实现选择排序法,对 lst_input 从小到大进行排序,排序结果保存到lst_rlt并输出。
|
|
16
|
+
|
|
17
|
+
程序分析:每一轮从当前未排序的后缀中选择最小元素,与该轮起始位置交换;下一轮处理范围缩短一个元素,直到列表有序。
|
|
18
|
+
请不要用 sort
|
|
19
|
+
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
# 参考答案
|
|
23
|
+
|
|
24
|
+
def TEST_DO_NOT_CHANGE(lst_input):
|
|
25
|
+
lst_rlt=[]
|
|
26
|
+
print(lst_input)
|
|
27
|
+
##########start下面可以改动
|
|
28
|
+
|
|
29
|
+
lst_rlt = lst_input.copy()
|
|
30
|
+
for start in range(len(lst_rlt) - 1):
|
|
31
|
+
smallest = start
|
|
32
|
+
for i in range(start + 1, len(lst_rlt)):
|
|
33
|
+
if lst_rlt[i] < lst_rlt[smallest]:
|
|
34
|
+
smallest = i
|
|
35
|
+
lst_rlt[start], lst_rlt[smallest] = lst_rlt[smallest], lst_rlt[start]
|
|
36
|
+
|
|
37
|
+
##########end上面可以改动
|
|
38
|
+
return lst_rlt
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
###########下面可以修改
|
|
43
|
+
print (TEST_DO_NOT_CHANGE([11,43,27,41,56,79,98,75,3,66]))
|