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,49 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定字符串 input_str(不调用 input(),换行符如出现在字符串中也按普通字符处理),
|
|
16
|
+
分别统计出其中英文字母、空格、数字和其它字符的个数,
|
|
17
|
+
并将结果依次保存到列表lst_rlt.
|
|
18
|
+
输出示例:[中英文字母个数,空格个数,数字个数,其他字符个数]
|
|
19
|
+
|
|
20
|
+
程序分析:遍历传入的字符串,并按字符类别分别计数。
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
# 参考答案
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def TEST_DO_NOT_CHANGE(input_str):
|
|
27
|
+
lst_rlt=[]
|
|
28
|
+
##########start下面可以改动
|
|
29
|
+
|
|
30
|
+
# 采用题目输出说明的“中英文字母”,用 isalpha 识别字母。
|
|
31
|
+
lst_rlt = [0, 0, 0, 0]
|
|
32
|
+
for char in input_str:
|
|
33
|
+
if char.isalpha():
|
|
34
|
+
lst_rlt[0] += 1
|
|
35
|
+
elif char == " ":
|
|
36
|
+
lst_rlt[1] += 1
|
|
37
|
+
elif char.isdigit():
|
|
38
|
+
lst_rlt[2] += 1
|
|
39
|
+
else:
|
|
40
|
+
lst_rlt[3] += 1
|
|
41
|
+
|
|
42
|
+
##########end上面可以改动
|
|
43
|
+
return lst_rlt
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
###########下面可以修改
|
|
48
|
+
print (TEST_DO_NOT_CHANGE('123runoobc kdf235*(dfl)'))
|
|
49
|
+
# 题号:hwc221
|
|
@@ -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
|
+
请将数据集 data 归一化到 0 和 1 之间。
|
|
16
|
+
提示:对每个 x 使用 min-max 归一化公式
|
|
17
|
+
x' = (x - min(data)) / (max(data) - min(data))。
|
|
18
|
+
例如data = [5, 20, 35, 50, 65],归一化后的值为[0.0, 0.25, 0.5, 0.75, 1.0]
|
|
19
|
+
请将下列数据集进行归一化并输出结果,结果请保留小数点后 2 位;当所有元素相等时返回全 0 列表。
|
|
20
|
+
data1 = [2,8,16,32,64]
|
|
21
|
+
data2 = [3,9,27,45,72]
|
|
22
|
+
data3 = [6,18,42,48,78]
|
|
23
|
+
'''
|
|
24
|
+
|
|
25
|
+
# 参考答案
|
|
26
|
+
def TEST_DO_NOT_CHANGE(data):
|
|
27
|
+
print(data)
|
|
28
|
+
result = None
|
|
29
|
+
##########start下面可以改动
|
|
30
|
+
|
|
31
|
+
if not data:
|
|
32
|
+
return []
|
|
33
|
+
low, high = min(data), max(data)
|
|
34
|
+
if high == low:
|
|
35
|
+
result = [0.0] * len(data)
|
|
36
|
+
else:
|
|
37
|
+
result = [round((value - low) / (high - low), 2) for value in data]
|
|
38
|
+
|
|
39
|
+
##########end上面可以改动
|
|
40
|
+
return result
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
###########下面可以修改
|
|
43
|
+
data1 = [2,8,16,32,64]
|
|
44
|
+
data2 = [3,9,27,45,72]
|
|
45
|
+
data3 = [6,18,42,48,78]
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(data1))
|
|
47
|
+
print(TEST_DO_NOT_CHANGE(data2))
|
|
48
|
+
print(TEST_DO_NOT_CHANGE(data3))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:最大公约数(GCD)
|
|
14
|
+
|
|
15
|
+
编写一个 Python 程序,接受两个正整数作为输入,并计算它们的最大公约数(GCD)。
|
|
16
|
+
|
|
17
|
+
最大公约数是两个或多个整数的共有因子中的最大值。例如,18 和 24 的最大公约数是 6。
|
|
18
|
+
|
|
19
|
+
编写一个函数 TEST_DO_NOT_CHANGE(a, b),它接受两个正整数 a 和 b 作为参数,返回它们的最大公约数。
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
# 参考答案
|
|
23
|
+
|
|
24
|
+
def TEST_DO_NOT_CHANGE(a, b):
|
|
25
|
+
gcd_result = None
|
|
26
|
+
##########start下面可以改动
|
|
27
|
+
|
|
28
|
+
while b:
|
|
29
|
+
a, b = b, a % b
|
|
30
|
+
gcd_result = a
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return gcd_result
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
###########下面可以修改
|
|
37
|
+
print(TEST_DO_NOT_CHANGE(16,256))
|
|
38
|
+
print(TEST_DO_NOT_CHANGE(27,36))
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(55,121))
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:计算阶乘
|
|
14
|
+
|
|
15
|
+
题目:
|
|
16
|
+
定义函数求阶乘:
|
|
17
|
+
要求对参数进行判断,对合法的参数求阶乘,参数零的阶乘返回1, 并在参数为负数时输出-1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
阶乘的定义如下:
|
|
21
|
+
|
|
22
|
+
0 的阶乘是 1。
|
|
23
|
+
正整数 n 的阶乘是所有小于等于 n 的正整数的乘积。
|
|
24
|
+
例如,5 的阶乘是 5 * 4 * 3 * 2 * 1 = 120。
|
|
25
|
+
'''
|
|
26
|
+
|
|
27
|
+
# 参考答案
|
|
28
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
29
|
+
rlt = None
|
|
30
|
+
##########start下面可以改动
|
|
31
|
+
|
|
32
|
+
if not isinstance(n, int) or n < 0:
|
|
33
|
+
return -1
|
|
34
|
+
rlt = 1
|
|
35
|
+
for factor in range(2, n + 1):
|
|
36
|
+
rlt *= factor
|
|
37
|
+
|
|
38
|
+
##########end上面可以改动
|
|
39
|
+
return rlt
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
###########下面可以修改
|
|
43
|
+
print(TEST_DO_NOT_CHANGE(10))
|
|
44
|
+
print(TEST_DO_NOT_CHANGE(12))
|
|
45
|
+
print(TEST_DO_NOT_CHANGE(7))
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(0)) # 0! = 1
|
|
47
|
+
print(TEST_DO_NOT_CHANGE(-3)) # 负数返回 -1
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:移动零元素
|
|
14
|
+
给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
|
|
15
|
+
|
|
16
|
+
请注意 ,必须在不复制数组的情况下原地对数组进行操作("原地"即直接在原数组 nums 上修改,不新建等长的新列表)。
|
|
17
|
+
注:本题为进阶版;基础版(返回新列表即可)见 hwc202。
|
|
18
|
+
|
|
19
|
+
示例 1:
|
|
20
|
+
|
|
21
|
+
输入: nums = [0,1,0,3,12]
|
|
22
|
+
输出: [1,3,12,0,0];函数应原地修改 nums,并返回修改后的 nums。
|
|
23
|
+
|
|
24
|
+
示例 2:
|
|
25
|
+
|
|
26
|
+
输入: nums = [0]
|
|
27
|
+
输出: [0]
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
32
|
+
print(nums)
|
|
33
|
+
##########start下面可以改动
|
|
34
|
+
|
|
35
|
+
write = 0
|
|
36
|
+
for value in nums:
|
|
37
|
+
if value != 0:
|
|
38
|
+
nums[write] = value
|
|
39
|
+
write += 1
|
|
40
|
+
for i in range(write, len(nums)):
|
|
41
|
+
nums[i] = 0
|
|
42
|
+
|
|
43
|
+
##########end上面可以改动
|
|
44
|
+
return nums
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
###########下面可以修改
|
|
48
|
+
print(TEST_DO_NOT_CHANGE([1,2,1,0,3,0,2,5]))
|
|
49
|
+
print(TEST_DO_NOT_CHANGE([1,0,-1]))
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([0,1]))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:查找质数的和
|
|
14
|
+
|
|
15
|
+
编写一个 Python 程序,查找并输出从 2 到 n 之间的所有质数的和。
|
|
16
|
+
|
|
17
|
+
质数是指只能被 1 和自身整除的正整数。例如,2、3、5、7、11 等都是质数。
|
|
18
|
+
|
|
19
|
+
编写一个函数 TEST_DO_NOT_CHANGE(num),它返回从 2 到 num 之间的所有质数的和。
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
# 参考答案
|
|
23
|
+
|
|
24
|
+
def TEST_DO_NOT_CHANGE(num):
|
|
25
|
+
prime_sum = 0
|
|
26
|
+
##########start下面可以改动
|
|
27
|
+
|
|
28
|
+
from math import isqrt
|
|
29
|
+
|
|
30
|
+
for value in range(2, num + 1):
|
|
31
|
+
if all(value % divisor != 0 for divisor in range(2, isqrt(value) + 1)):
|
|
32
|
+
prime_sum += value
|
|
33
|
+
|
|
34
|
+
##########end上面可以改动
|
|
35
|
+
return prime_sum
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
###########下面可以修改
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(100))
|
|
40
|
+
print(TEST_DO_NOT_CHANGE(120))
|
|
41
|
+
print(TEST_DO_NOT_CHANGE(150))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
两个 3 行 3 列的矩阵X、Y,实现其对应位置的数据相加,并返回一个新矩阵rlt_Z
|
|
16
|
+
X = [[12,7,3],[4 ,5,6],[7 ,8,9]]
|
|
17
|
+
Y = [[5,8,1],[6,7,3],[4,5,9]]
|
|
18
|
+
'''
|
|
19
|
+
|
|
20
|
+
# 参考答案
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def TEST_DO_NOT_CHANGE(X,Y):
|
|
25
|
+
print(X,Y)
|
|
26
|
+
rlt_Z = None
|
|
27
|
+
##########start下面可以改动
|
|
28
|
+
|
|
29
|
+
rlt_Z = [[x + y for x, y in zip(row_x, row_y)] for row_x, row_y in zip(X, Y)]
|
|
30
|
+
|
|
31
|
+
##########end上面可以改动
|
|
32
|
+
return rlt_Z
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
###########下面可以修改
|
|
38
|
+
X = [[12,7,3],[4 ,5,6],[7 ,8,9]]
|
|
39
|
+
Y = [[5,8,1],[6,7,3],[4,5,9]]
|
|
40
|
+
print (TEST_DO_NOT_CHANGE(X,Y))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
整数反转,给你一个 32 位的有符号整数 x(取值范围 -2147483648 到 2147483647),返回将 x 中的数字部分反转后的结果。
|
|
16
|
+
例如: 整数为12345,反转后result 输出:54321
|
|
17
|
+
|
|
18
|
+
如果反转后整数超过上述范围(即小于 -2**31 或大于 2**31 − 1),就返回 0。
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
# 参考答案
|
|
22
|
+
|
|
23
|
+
def TEST_DO_NOT_CHANGE(x):
|
|
24
|
+
print(x)
|
|
25
|
+
result = 0
|
|
26
|
+
##########start下面可以改动
|
|
27
|
+
|
|
28
|
+
reversed_value = int(str(abs(x))[::-1])
|
|
29
|
+
if x < 0:
|
|
30
|
+
reversed_value = -reversed_value
|
|
31
|
+
if -(2 ** 31) <= reversed_value < 2 ** 31:
|
|
32
|
+
result = reversed_value
|
|
33
|
+
|
|
34
|
+
##########end上面可以改动
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
###########下面可以修改
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(1589456))
|
|
40
|
+
print(TEST_DO_NOT_CHANGE(565893))
|
|
41
|
+
print(TEST_DO_NOT_CHANGE(-2147483648))
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
将两个升序列表合并为一个新的升序列表并返回。输入使用 Python list,不涉及链表结点。
|
|
16
|
+
|
|
17
|
+
示例:
|
|
18
|
+
输入:l1 = [1,2,4], l2 = [1,3,4]
|
|
19
|
+
输出:[1,1,2,3,4,4]
|
|
20
|
+
|
|
21
|
+
输入:l1 = [], l2 = [0]
|
|
22
|
+
输出:[0]
|
|
23
|
+
'''
|
|
24
|
+
|
|
25
|
+
# 参考答案
|
|
26
|
+
|
|
27
|
+
def TEST_DO_NOT_CHANGE(l1, l2):
|
|
28
|
+
print(l1, l2)
|
|
29
|
+
merged = None
|
|
30
|
+
##########start下面可以改动
|
|
31
|
+
|
|
32
|
+
merged = []
|
|
33
|
+
i = j = 0
|
|
34
|
+
while i < len(l1) and j < len(l2):
|
|
35
|
+
if l1[i] <= l2[j]:
|
|
36
|
+
merged.append(l1[i])
|
|
37
|
+
i += 1
|
|
38
|
+
else:
|
|
39
|
+
merged.append(l2[j])
|
|
40
|
+
j += 1
|
|
41
|
+
merged.extend(l1[i:])
|
|
42
|
+
merged.extend(l2[j:])
|
|
43
|
+
|
|
44
|
+
##########end上面可以改动
|
|
45
|
+
return merged
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
###########下面可以修改
|
|
49
|
+
print(TEST_DO_NOT_CHANGE( [1,2,4],[1,3,4]))
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([],[]))
|
|
51
|
+
print(TEST_DO_NOT_CHANGE([],[0]))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
寻找峰值,给出峰值在列表中的索引值; 峰值元素是指其值严格大于左右相邻值的元素,峰值元素不会出现在首尾。
|
|
16
|
+
例如nums = [1, 2, 1, 3, 5, 6, 4, 3, 7, 3, 8],其中峰值为2、6、7这三个元素,最后输出这三个峰值的索引值即 :[1, 5, 8]。
|
|
17
|
+
现有以下几个列表,分别找出其中的峰值并输出峰值在其列表中的索引号。
|
|
18
|
+
num1 = [2,4,3,1,3,5,8,1,4,1,2]
|
|
19
|
+
num2 = [2,1,3,1,2,7,2,3,2,5,6]
|
|
20
|
+
num3 = [9,2,1,1,3,2,8,1,1,3,6]
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
# 参考答案
|
|
24
|
+
|
|
25
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
26
|
+
result = None
|
|
27
|
+
print(nums)
|
|
28
|
+
##########start下面可以改动
|
|
29
|
+
|
|
30
|
+
result = [i for i in range(1, len(nums) - 1) if nums[i - 1] < nums[i] > nums[i + 1]]
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return result
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
###########下面可以修改
|
|
36
|
+
num1 = [2,4,3,1,3,5,8,1,4,1,2]
|
|
37
|
+
num2 = [2,1,3,1,2,7,2,3,2,5,6]
|
|
38
|
+
num3 = [9,2,1,1,3,2,8,1,1,3,6]
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(num1))
|
|
40
|
+
print(TEST_DO_NOT_CHANGE(num2))
|
|
41
|
+
print(TEST_DO_NOT_CHANGE(num3))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
有34个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
|
|
16
|
+
'''
|
|
17
|
+
|
|
18
|
+
# 参考答案
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def TEST_DO_NOT_CHANGE():
|
|
22
|
+
i_rlt = None
|
|
23
|
+
##########start下面可以改动
|
|
24
|
+
|
|
25
|
+
people = list(range(1, 35))
|
|
26
|
+
index = 0
|
|
27
|
+
while len(people) > 1:
|
|
28
|
+
index = (index + 2) % len(people)
|
|
29
|
+
people.pop(index)
|
|
30
|
+
i_rlt = people[0]
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return i_rlt
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
###########下面可以修改
|
|
39
|
+
print (TEST_DO_NOT_CHANGE())
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
实现一个函数,该函数接受一个字符串 email 作为参数,返回一个布尔值表示该字符串是否为有效的电子邮箱地址。
|
|
16
|
+
以下是有效电子邮箱地址的一些基本规则(这只是一个简化版本,实际的电子邮箱验证可能更加复杂):
|
|
17
|
+
必须且只能包含一个 "@";本地部分和域名部分均非空,且不能含空格。
|
|
18
|
+
域名部分至少包含一个 ".",不能以 "." 开头或结尾,也不能含连续的点。
|
|
19
|
+
最后一个 "." 后的顶级域名长度为 2 至 5 个英文字母。
|
|
20
|
+
|
|
21
|
+
例如:"example@.",由于 .后没有字符,因此不符合标准,应该返回的结果为: False
|
|
22
|
+
'''
|
|
23
|
+
|
|
24
|
+
# 参考答案
|
|
25
|
+
import re
|
|
26
|
+
def TEST_DO_NOT_CHANGE(email):
|
|
27
|
+
result = None
|
|
28
|
+
##########start下面可以改动
|
|
29
|
+
|
|
30
|
+
result = re.fullmatch(r"[^@\s]+@(?:[^@.\s]+\.)+[A-Za-z]{2,5}", email) is not None
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return result
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
###########下面可以修改
|
|
37
|
+
print(TEST_DO_NOT_CHANGE("example@email.com"))
|
|
38
|
+
print(TEST_DO_NOT_CHANGE("example@email"))
|
|
39
|
+
print(TEST_DO_NOT_CHANGE("example.com"))
|
|
40
|
+
print(TEST_DO_NOT_CHANGE("example@.com"))
|
|
41
|
+
print(TEST_DO_NOT_CHANGE("a@@b.com"))
|
|
42
|
+
print(TEST_DO_NOT_CHANGE("a@b..com"))
|
|
43
|
+
print(TEST_DO_NOT_CHANGE("a@b.c"))
|
|
44
|
+
# 题号:hwc232
|
|
@@ -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
|
+
企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;
|
|
16
|
+
利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;
|
|
17
|
+
20万到40万之间时,高于20万元的部分,可提成5%;
|
|
18
|
+
40万到60万之间时高于40万元的部分,可提成3%;
|
|
19
|
+
60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成。
|
|
20
|
+
如果给定利润V,求应发放奖金总数?
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
程序分析:请利用数轴来分界,定位。
|
|
24
|
+
'''
|
|
25
|
+
|
|
26
|
+
# 参考答案
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def TEST_DO_NOT_CHANGE(V):
|
|
30
|
+
rlt = None
|
|
31
|
+
##########start下面可以改动
|
|
32
|
+
|
|
33
|
+
rlt = 0
|
|
34
|
+
lower = 0
|
|
35
|
+
for upper, rate in ((100_000, .10), (200_000, .075), (400_000, .05),
|
|
36
|
+
(600_000, .03), (1_000_000, .015), (float("inf"), .01)):
|
|
37
|
+
rlt += max(0, min(V, upper) - lower) * rate
|
|
38
|
+
if V <= upper:
|
|
39
|
+
break
|
|
40
|
+
lower = upper
|
|
41
|
+
|
|
42
|
+
##########end上面可以改动
|
|
43
|
+
return rlt
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
###########下面可以修改
|
|
48
|
+
print (TEST_DO_NOT_CHANGE(120000))
|
|
49
|
+
print (TEST_DO_NOT_CHANGE(1200000))
|
|
@@ -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
|
+
定义一个函数f(s),统计s中(按字典序比较)最小字母的出现频次,其中s是一个非空字符串。
|
|
16
|
+
例如,若s = "dcce",那么f(s) = 2,因为字典序最小字母是"c",它出现了2 次。
|
|
17
|
+
现在给你两个字符串数组:待查表 queries 和词汇表 words。
|
|
18
|
+
对每次查询 queries[i],请统计 words 中有多少个单词 W 满足 f(W) > f(queries[i])(即这个词的最小字母出现频次比查询词的更大)。
|
|
19
|
+
请你返回一个整数数组 answer 作为答案,其中 answer[i] 是第 i 次查询的统计结果。
|
|
20
|
+
|
|
21
|
+
示例:
|
|
22
|
+
输入:queries = ["cbd"], words = ["zaaaz"]
|
|
23
|
+
输出:[1]
|
|
24
|
+
|
|
25
|
+
提示:
|
|
26
|
+
1 <= queries.length <= 2000
|
|
27
|
+
1 <= words.length <= 2000
|
|
28
|
+
1 <= queries[i].length, words[i].length <= 10
|
|
29
|
+
queries[i][j]、words[i][j]都由小写英文字母组成
|
|
30
|
+
'''
|
|
31
|
+
|
|
32
|
+
# 参考答案
|
|
33
|
+
|
|
34
|
+
def TEST_DO_NOT_CHANGE(queries, words):
|
|
35
|
+
lst_rlt = []
|
|
36
|
+
##########start下面可以改动
|
|
37
|
+
|
|
38
|
+
from bisect import bisect_right
|
|
39
|
+
|
|
40
|
+
def frequency(word):
|
|
41
|
+
return word.count(min(word))
|
|
42
|
+
|
|
43
|
+
frequencies = sorted(frequency(word) for word in words)
|
|
44
|
+
lst_rlt = [len(words) - bisect_right(frequencies, frequency(query)) for query in queries]
|
|
45
|
+
|
|
46
|
+
##########end上面可以改动
|
|
47
|
+
return lst_rlt
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
###########下面可以修改
|
|
51
|
+
print(TEST_DO_NOT_CHANGE(["cbd"],["zaaaz"]))
|
|
52
|
+
# 题号:hwc234
|
|
@@ -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
|
+
例如:"Hello world! This is a test. This is only a test.",应输出{'hello': 1, 'world': 1, 'this': 2, 'is': 2, 'a': 2, 'test': 2, 'only': 1}
|
|
17
|
+
计算并显示以下文本中每个单词的出现频率。
|
|
18
|
+
text1 = "Far from eye, far from heart."
|
|
19
|
+
text2 = "Fields have eyes, and woods have ears."
|
|
20
|
+
text3 = "Good for good is natural, good for evil is manly."
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
# 参考答案
|
|
24
|
+
import re
|
|
25
|
+
def TEST_DO_NOT_CHANGE(text):
|
|
26
|
+
result = None
|
|
27
|
+
print(text)
|
|
28
|
+
|
|
29
|
+
##########start下面可以改动
|
|
30
|
+
|
|
31
|
+
from collections import Counter
|
|
32
|
+
|
|
33
|
+
result = dict(Counter(re.findall(r"[^\W\d_]+", text.lower())))
|
|
34
|
+
|
|
35
|
+
##########end上面可以改动
|
|
36
|
+
return result
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
###########下面可以修改
|
|
39
|
+
text1 = "Far from eye, far from heart."
|
|
40
|
+
text2 = "Fields have eyes, and woods have ears."
|
|
41
|
+
text3 = "Good for good is natural, good for evil is manly."
|
|
42
|
+
print(TEST_DO_NOT_CHANGE(text1))
|
|
43
|
+
print(TEST_DO_NOT_CHANGE(text2))
|
|
44
|
+
print(TEST_DO_NOT_CHANGE(text3))
|
|
45
|
+
# 题号:hwc235
|