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.
Files changed (305) hide show
  1. bai_python_hwc/__init__.py +46 -0
  2. bai_python_hwc/answers/hwc101.py +38 -0
  3. bai_python_hwc/answers/hwc103.py +52 -0
  4. bai_python_hwc/answers/hwc104.py +45 -0
  5. bai_python_hwc/answers/hwc105.py +45 -0
  6. bai_python_hwc/answers/hwc106.py +56 -0
  7. bai_python_hwc/answers/hwc107.py +49 -0
  8. bai_python_hwc/answers/hwc108.py +45 -0
  9. bai_python_hwc/answers/hwc109.py +50 -0
  10. bai_python_hwc/answers/hwc110.py +42 -0
  11. bai_python_hwc/answers/hwc111.py +47 -0
  12. bai_python_hwc/answers/hwc112.py +42 -0
  13. bai_python_hwc/answers/hwc113.py +58 -0
  14. bai_python_hwc/answers/hwc114.py +58 -0
  15. bai_python_hwc/answers/hwc115.py +38 -0
  16. bai_python_hwc/answers/hwc116.py +44 -0
  17. bai_python_hwc/answers/hwc117.py +46 -0
  18. bai_python_hwc/answers/hwc118.py +47 -0
  19. bai_python_hwc/answers/hwc119.py +44 -0
  20. bai_python_hwc/answers/hwc120.py +41 -0
  21. bai_python_hwc/answers/hwc121.py +50 -0
  22. bai_python_hwc/answers/hwc122.py +54 -0
  23. bai_python_hwc/answers/hwc123.py +43 -0
  24. bai_python_hwc/answers/hwc124.py +41 -0
  25. bai_python_hwc/answers/hwc125.py +52 -0
  26. bai_python_hwc/answers/hwc126.py +40 -0
  27. bai_python_hwc/answers/hwc127.py +41 -0
  28. bai_python_hwc/answers/hwc128.py +39 -0
  29. bai_python_hwc/answers/hwc130.py +46 -0
  30. bai_python_hwc/answers/hwc131.py +46 -0
  31. bai_python_hwc/answers/hwc132.py +38 -0
  32. bai_python_hwc/answers/hwc133.py +61 -0
  33. bai_python_hwc/answers/hwc134.py +45 -0
  34. bai_python_hwc/answers/hwc135.py +49 -0
  35. bai_python_hwc/answers/hwc136.py +43 -0
  36. bai_python_hwc/answers/hwc201.py +47 -0
  37. bai_python_hwc/answers/hwc202.py +47 -0
  38. bai_python_hwc/answers/hwc203.py +48 -0
  39. bai_python_hwc/answers/hwc204.py +61 -0
  40. bai_python_hwc/answers/hwc205.py +56 -0
  41. bai_python_hwc/answers/hwc206.py +53 -0
  42. bai_python_hwc/answers/hwc207.py +43 -0
  43. bai_python_hwc/answers/hwc208.py +57 -0
  44. bai_python_hwc/answers/hwc209.py +42 -0
  45. bai_python_hwc/answers/hwc210.py +46 -0
  46. bai_python_hwc/answers/hwc211.py +62 -0
  47. bai_python_hwc/answers/hwc212.py +58 -0
  48. bai_python_hwc/answers/hwc213.py +54 -0
  49. bai_python_hwc/answers/hwc214.py +55 -0
  50. bai_python_hwc/answers/hwc215.py +53 -0
  51. bai_python_hwc/answers/hwc216.py +50 -0
  52. bai_python_hwc/answers/hwc217.py +38 -0
  53. bai_python_hwc/answers/hwc218.py +44 -0
  54. bai_python_hwc/answers/hwc219.py +49 -0
  55. bai_python_hwc/answers/hwc220.py +58 -0
  56. bai_python_hwc/answers/hwc221.py +49 -0
  57. bai_python_hwc/answers/hwc222.py +48 -0
  58. bai_python_hwc/answers/hwc223.py +39 -0
  59. bai_python_hwc/answers/hwc224.py +47 -0
  60. bai_python_hwc/answers/hwc225.py +50 -0
  61. bai_python_hwc/answers/hwc226.py +41 -0
  62. bai_python_hwc/answers/hwc227.py +40 -0
  63. bai_python_hwc/answers/hwc228.py +41 -0
  64. bai_python_hwc/answers/hwc229.py +51 -0
  65. bai_python_hwc/answers/hwc230.py +41 -0
  66. bai_python_hwc/answers/hwc231.py +39 -0
  67. bai_python_hwc/answers/hwc232.py +44 -0
  68. bai_python_hwc/answers/hwc233.py +49 -0
  69. bai_python_hwc/answers/hwc234.py +52 -0
  70. bai_python_hwc/answers/hwc235.py +45 -0
  71. bai_python_hwc/answers/hwc236.py +53 -0
  72. bai_python_hwc/answers/hwc237.py +56 -0
  73. bai_python_hwc/answers/hwc238.py +52 -0
  74. bai_python_hwc/answers/hwc239.py +60 -0
  75. bai_python_hwc/answers/hwc240.py +45 -0
  76. bai_python_hwc/answers/hwc241.py +48 -0
  77. bai_python_hwc/answers/hwc242.py +50 -0
  78. bai_python_hwc/answers/hwc243.py +61 -0
  79. bai_python_hwc/answers/hwc244.py +61 -0
  80. bai_python_hwc/answers/hwc245.py +47 -0
  81. bai_python_hwc/answers/hwc246.py +52 -0
  82. bai_python_hwc/answers/hwc247.py +76 -0
  83. bai_python_hwc/answers/hwc301.py +44 -0
  84. bai_python_hwc/answers/hwc302.py +53 -0
  85. bai_python_hwc/answers/hwc303.py +63 -0
  86. bai_python_hwc/answers/hwc304.py +56 -0
  87. bai_python_hwc/answers/hwc305.py +59 -0
  88. bai_python_hwc/answers/hwc306.py +60 -0
  89. bai_python_hwc/answers/hwc307.py +50 -0
  90. bai_python_hwc/answers/hwc308.py +59 -0
  91. bai_python_hwc/answers/hwc309.py +48 -0
  92. bai_python_hwc/answers/hwc310.py +38 -0
  93. bai_python_hwc/answers/hwc311.py +48 -0
  94. bai_python_hwc/answers/hwc312.py +49 -0
  95. bai_python_hwc/answers/hwc313.py +54 -0
  96. bai_python_hwc/answers/hwc314.py +49 -0
  97. bai_python_hwc/answers/hwc315.py +63 -0
  98. bai_python_hwc/answers/hwc316.py +65 -0
  99. bai_python_hwc/answers/hwc317.py +57 -0
  100. bai_python_hwc/answers/hwc318.py +55 -0
  101. bai_python_hwc/answers/hwc319.py +50 -0
  102. bai_python_hwc/answers/hwc320.py +84 -0
  103. bai_python_hwc/answers/hwc321.py +49 -0
  104. bai_python_hwc/answers/hwc322.py +49 -0
  105. bai_python_hwc/answers/hwc323.py +69 -0
  106. bai_python_hwc/answers/hwc324.py +66 -0
  107. bai_python_hwc/answers/hwc325.py +49 -0
  108. bai_python_hwc/answers/hwc326.py +53 -0
  109. bai_python_hwc/answers/hwc327.py +38 -0
  110. bai_python_hwc/answers/hwc328.py +50 -0
  111. bai_python_hwc/answers/hwc329.py +59 -0
  112. bai_python_hwc/answers/hwc330.py +45 -0
  113. bai_python_hwc/answers/hwc332.py +57 -0
  114. bai_python_hwc/answers/hwc401.py +50 -0
  115. bai_python_hwc/answers/hwc402.py +43 -0
  116. bai_python_hwc/answers/hwc403.py +73 -0
  117. bai_python_hwc/answers/hwc404.py +51 -0
  118. bai_python_hwc/answers/hwc405.py +62 -0
  119. bai_python_hwc/answers/hwc406.py +66 -0
  120. bai_python_hwc/answers/hwc407.py +49 -0
  121. bai_python_hwc/answers/hwc408.py +67 -0
  122. bai_python_hwc/answers/hwc409.py +51 -0
  123. bai_python_hwc/answers/hwc410.py +52 -0
  124. bai_python_hwc/answers/hwc411.py +57 -0
  125. bai_python_hwc/answers/hwc412.py +53 -0
  126. bai_python_hwc/answers/hwc413.py +65 -0
  127. bai_python_hwc/answers/hwc414.py +50 -0
  128. bai_python_hwc/answers/hwc415.py +61 -0
  129. bai_python_hwc/answers/hwc416.py +69 -0
  130. bai_python_hwc/answers/hwc418.py +47 -0
  131. bai_python_hwc/answers/hwc419.py +62 -0
  132. bai_python_hwc/answers/hwc421.py +51 -0
  133. bai_python_hwc/answers/hwc424.py +48 -0
  134. bai_python_hwc/answers/hwc501.py +63 -0
  135. bai_python_hwc/answers/hwc502.py +69 -0
  136. bai_python_hwc/answers/hwc503.py +75 -0
  137. bai_python_hwc/answers/hwc504.py +52 -0
  138. bai_python_hwc/answers/hwc505.py +63 -0
  139. bai_python_hwc/answers/hwc506.py +61 -0
  140. bai_python_hwc/answers/hwc508.py +60 -0
  141. bai_python_hwc/answers/hwc509.py +85 -0
  142. bai_python_hwc/answers/hwc510.py +56 -0
  143. bai_python_hwc/answers/hwc511.py +52 -0
  144. bai_python_hwc/answers/hwc513.py +63 -0
  145. bai_python_hwc/answers/hwc514.py +74 -0
  146. bai_python_hwc/answers/hwc515.py +83 -0
  147. bai_python_hwc/answers/hwc516.py +67 -0
  148. bai_python_hwc/answers/hwc517.py +46 -0
  149. bai_python_hwc/answers/hwc520.py +54 -0
  150. bai_python_hwc/answers/hwc526.py +58 -0
  151. bai_python_hwc/attachments/hwc424.pdf +0 -0
  152. bai_python_hwc/attachments/hwc501.pdf +0 -0
  153. bai_python_hwc/questions/hwc101.txt +17 -0
  154. bai_python_hwc/questions/hwc103.txt +27 -0
  155. bai_python_hwc/questions/hwc104.txt +22 -0
  156. bai_python_hwc/questions/hwc105.txt +23 -0
  157. bai_python_hwc/questions/hwc106.txt +26 -0
  158. bai_python_hwc/questions/hwc107.txt +29 -0
  159. bai_python_hwc/questions/hwc108.txt +18 -0
  160. bai_python_hwc/questions/hwc109.txt +24 -0
  161. bai_python_hwc/questions/hwc110.txt +16 -0
  162. bai_python_hwc/questions/hwc111.txt +25 -0
  163. bai_python_hwc/questions/hwc112.txt +13 -0
  164. bai_python_hwc/questions/hwc113.txt +28 -0
  165. bai_python_hwc/questions/hwc114.txt +35 -0
  166. bai_python_hwc/questions/hwc115.txt +15 -0
  167. bai_python_hwc/questions/hwc116.txt +13 -0
  168. bai_python_hwc/questions/hwc117.txt +14 -0
  169. bai_python_hwc/questions/hwc118.txt +25 -0
  170. bai_python_hwc/questions/hwc119.txt +18 -0
  171. bai_python_hwc/questions/hwc120.txt +23 -0
  172. bai_python_hwc/questions/hwc121.txt +26 -0
  173. bai_python_hwc/questions/hwc122.txt +21 -0
  174. bai_python_hwc/questions/hwc123.txt +21 -0
  175. bai_python_hwc/questions/hwc124.txt +19 -0
  176. bai_python_hwc/questions/hwc125.txt +31 -0
  177. bai_python_hwc/questions/hwc126.txt +18 -0
  178. bai_python_hwc/questions/hwc127.txt +17 -0
  179. bai_python_hwc/questions/hwc128.txt +14 -0
  180. bai_python_hwc/questions/hwc130.txt +23 -0
  181. bai_python_hwc/questions/hwc131.txt +19 -0
  182. bai_python_hwc/questions/hwc132.txt +16 -0
  183. bai_python_hwc/questions/hwc133.txt +39 -0
  184. bai_python_hwc/questions/hwc134.txt +22 -0
  185. bai_python_hwc/questions/hwc135.txt +29 -0
  186. bai_python_hwc/questions/hwc136.txt +20 -0
  187. bai_python_hwc/questions/hwc201.txt +20 -0
  188. bai_python_hwc/questions/hwc202.txt +25 -0
  189. bai_python_hwc/questions/hwc203.txt +26 -0
  190. bai_python_hwc/questions/hwc204.txt +32 -0
  191. bai_python_hwc/questions/hwc205.txt +28 -0
  192. bai_python_hwc/questions/hwc206.txt +28 -0
  193. bai_python_hwc/questions/hwc207.txt +16 -0
  194. bai_python_hwc/questions/hwc208.txt +27 -0
  195. bai_python_hwc/questions/hwc209.txt +15 -0
  196. bai_python_hwc/questions/hwc210.txt +28 -0
  197. bai_python_hwc/questions/hwc211.txt +35 -0
  198. bai_python_hwc/questions/hwc212.txt +29 -0
  199. bai_python_hwc/questions/hwc213.txt +27 -0
  200. bai_python_hwc/questions/hwc214.txt +27 -0
  201. bai_python_hwc/questions/hwc215.txt +28 -0
  202. bai_python_hwc/questions/hwc216.txt +22 -0
  203. bai_python_hwc/questions/hwc217.txt +17 -0
  204. bai_python_hwc/questions/hwc218.txt +18 -0
  205. bai_python_hwc/questions/hwc219.txt +22 -0
  206. bai_python_hwc/questions/hwc220.txt +28 -0
  207. bai_python_hwc/questions/hwc221.txt +18 -0
  208. bai_python_hwc/questions/hwc222.txt +20 -0
  209. bai_python_hwc/questions/hwc223.txt +18 -0
  210. bai_python_hwc/questions/hwc224.txt +23 -0
  211. bai_python_hwc/questions/hwc225.txt +26 -0
  212. bai_python_hwc/questions/hwc226.txt +18 -0
  213. bai_python_hwc/questions/hwc227.txt +15 -0
  214. bai_python_hwc/questions/hwc228.txt +16 -0
  215. bai_python_hwc/questions/hwc229.txt +20 -0
  216. bai_python_hwc/questions/hwc230.txt +18 -0
  217. bai_python_hwc/questions/hwc231.txt +13 -0
  218. bai_python_hwc/questions/hwc232.txt +19 -0
  219. bai_python_hwc/questions/hwc233.txt +21 -0
  220. bai_python_hwc/questions/hwc234.txt +27 -0
  221. bai_python_hwc/questions/hwc235.txt +18 -0
  222. bai_python_hwc/questions/hwc236.txt +23 -0
  223. bai_python_hwc/questions/hwc237.txt +28 -0
  224. bai_python_hwc/questions/hwc238.txt +25 -0
  225. bai_python_hwc/questions/hwc239.txt +28 -0
  226. bai_python_hwc/questions/hwc240.txt +21 -0
  227. bai_python_hwc/questions/hwc241.txt +25 -0
  228. bai_python_hwc/questions/hwc242.txt +23 -0
  229. bai_python_hwc/questions/hwc243.txt +35 -0
  230. bai_python_hwc/questions/hwc244.txt +25 -0
  231. bai_python_hwc/questions/hwc245.txt +24 -0
  232. bai_python_hwc/questions/hwc246.txt +28 -0
  233. bai_python_hwc/questions/hwc247.txt +51 -0
  234. bai_python_hwc/questions/hwc301.txt +23 -0
  235. bai_python_hwc/questions/hwc302.txt +26 -0
  236. bai_python_hwc/questions/hwc303.txt +32 -0
  237. bai_python_hwc/questions/hwc304.txt +32 -0
  238. bai_python_hwc/questions/hwc305.txt +31 -0
  239. bai_python_hwc/questions/hwc306.txt +31 -0
  240. bai_python_hwc/questions/hwc307.txt +29 -0
  241. bai_python_hwc/questions/hwc308.txt +30 -0
  242. bai_python_hwc/questions/hwc309.txt +25 -0
  243. bai_python_hwc/questions/hwc310.txt +15 -0
  244. bai_python_hwc/questions/hwc311.txt +23 -0
  245. bai_python_hwc/questions/hwc312.txt +19 -0
  246. bai_python_hwc/questions/hwc313.txt +26 -0
  247. bai_python_hwc/questions/hwc314.txt +27 -0
  248. bai_python_hwc/questions/hwc315.txt +21 -0
  249. bai_python_hwc/questions/hwc316.txt +36 -0
  250. bai_python_hwc/questions/hwc317.txt +28 -0
  251. bai_python_hwc/questions/hwc318.txt +27 -0
  252. bai_python_hwc/questions/hwc319.txt +26 -0
  253. bai_python_hwc/questions/hwc320.txt +42 -0
  254. bai_python_hwc/questions/hwc321.txt +27 -0
  255. bai_python_hwc/questions/hwc322.txt +26 -0
  256. bai_python_hwc/questions/hwc323.txt +24 -0
  257. bai_python_hwc/questions/hwc324.txt +40 -0
  258. bai_python_hwc/questions/hwc325.txt +21 -0
  259. bai_python_hwc/questions/hwc326.txt +25 -0
  260. bai_python_hwc/questions/hwc327.txt +16 -0
  261. bai_python_hwc/questions/hwc328.txt +15 -0
  262. bai_python_hwc/questions/hwc329.txt +26 -0
  263. bai_python_hwc/questions/hwc330.txt +27 -0
  264. bai_python_hwc/questions/hwc332.txt +26 -0
  265. bai_python_hwc/questions/hwc401.txt +25 -0
  266. bai_python_hwc/questions/hwc402.txt +24 -0
  267. bai_python_hwc/questions/hwc403.txt +37 -0
  268. bai_python_hwc/questions/hwc404.txt +23 -0
  269. bai_python_hwc/questions/hwc405.txt +29 -0
  270. bai_python_hwc/questions/hwc406.txt +34 -0
  271. bai_python_hwc/questions/hwc407.txt +24 -0
  272. bai_python_hwc/questions/hwc408.txt +28 -0
  273. bai_python_hwc/questions/hwc409.txt +25 -0
  274. bai_python_hwc/questions/hwc410.txt +23 -0
  275. bai_python_hwc/questions/hwc411.txt +34 -0
  276. bai_python_hwc/questions/hwc412.txt +29 -0
  277. bai_python_hwc/questions/hwc413.txt +28 -0
  278. bai_python_hwc/questions/hwc414.txt +27 -0
  279. bai_python_hwc/questions/hwc415.txt +27 -0
  280. bai_python_hwc/questions/hwc416.txt +36 -0
  281. bai_python_hwc/questions/hwc418.txt +25 -0
  282. bai_python_hwc/questions/hwc419.txt +28 -0
  283. bai_python_hwc/questions/hwc421.txt +23 -0
  284. bai_python_hwc/questions/hwc424.txt +20 -0
  285. bai_python_hwc/questions/hwc501.txt +23 -0
  286. bai_python_hwc/questions/hwc502.txt +41 -0
  287. bai_python_hwc/questions/hwc503.txt +36 -0
  288. bai_python_hwc/questions/hwc504.txt +18 -0
  289. bai_python_hwc/questions/hwc505.txt +25 -0
  290. bai_python_hwc/questions/hwc506.txt +32 -0
  291. bai_python_hwc/questions/hwc508.txt +24 -0
  292. bai_python_hwc/questions/hwc509.txt +42 -0
  293. bai_python_hwc/questions/hwc510.txt +25 -0
  294. bai_python_hwc/questions/hwc511.txt +23 -0
  295. bai_python_hwc/questions/hwc513.txt +25 -0
  296. bai_python_hwc/questions/hwc514.txt +35 -0
  297. bai_python_hwc/questions/hwc515.txt +46 -0
  298. bai_python_hwc/questions/hwc516.txt +26 -0
  299. bai_python_hwc/questions/hwc517.txt +20 -0
  300. bai_python_hwc/questions/hwc520.txt +27 -0
  301. bai_python_hwc/questions/hwc526.txt +36 -0
  302. bai_python_hwc-1.0.0.dist-info/METADATA +41 -0
  303. bai_python_hwc-1.0.0.dist-info/RECORD +305 -0
  304. bai_python_hwc-1.0.0.dist-info/WHEEL +5 -0
  305. bai_python_hwc-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,62 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:给定两个以字符串形式表示的非负整数num1和num2,返回num1和num2的乘积,它们的乘积也表示为字符串形式。
15
+
16
+ 示例 1:
17
+
18
+ 输入: num1 = "2", num2 = "3"
19
+ 输出: "6"
20
+
21
+ 示例2:
22
+
23
+ 输入: num1 = "123", num2 = "456"
24
+ 输出: "56088"
25
+
26
+ 注意:
27
+ 1.num1和num2的长度小于110。
28
+ 2.num1 和num2 只包含数字0-9。
29
+ 3.num1 和num2均不以零开头,除非是数字 0 本身。
30
+ 4.不能使用任何标准库的大数类型(比如 BigInteger)或直接将输入转换为整数来处理。
31
+ '''
32
+
33
+ # 参考答案
34
+ def TEST_DO_NOT_CHANGE(num1,num2):
35
+ print(num1,num2)
36
+ str_rlt = None
37
+ ##########start下面可以改动
38
+
39
+ if num1 == "0" or num2 == "0":
40
+ return "0"
41
+ digits = [0] * (len(num1) + len(num2))
42
+ for i in range(len(num1) - 1, -1, -1):
43
+ for j in range(len(num2) - 1, -1, -1):
44
+ position = i + j + 1
45
+ product = int(num1[i]) * int(num2[j]) + digits[position]
46
+ carry, digits[position] = divmod(product, 10)
47
+ digits[position - 1] += carry
48
+ str_rlt = "".join(map(str, digits)).lstrip("0")
49
+
50
+ ##########end上面可以改动
51
+ return str_rlt
52
+
53
+ if __name__ == "__main__":
54
+ ###########下面可以修改
55
+ num1 = "2"
56
+ num2 = "3"
57
+ print(TEST_DO_NOT_CHANGE(num1,num2))
58
+
59
+
60
+
61
+
62
+ # 题号:hwc419
@@ -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
+ 返回所有长度为n且满足其每两个连续位上的数字之间的差的绝对值为k的非负整数。
16
+ 请注意除了数字0本身之外,答案中的每个数字都不能有前导零。例如01有一个前导零,所以是无效的,但0是有效的。
17
+ 你可以按任何顺序返回答案。
18
+
19
+ 示例:
20
+ 输入:n=3,k=7
21
+ 输出:[181,292,707,818,929]
22
+
23
+ 提示:
24
+ 2 <= n <= 9
25
+ 0 <= k <= 9
26
+ '''
27
+
28
+ # 参考答案
29
+
30
+ def TEST_DO_NOT_CHANGE(n, k):
31
+ lst_rlt = []
32
+ ##########start下面可以改动
33
+
34
+ lst_rlt = list(range(10)) if n == 1 else list(range(1, 10))
35
+ for _ in range(n - 1):
36
+ next_values = []
37
+ for value in lst_rlt:
38
+ last = value % 10
39
+ for digit in sorted({last - k, last + k}):
40
+ if 0 <= digit <= 9:
41
+ next_values.append(value * 10 + digit)
42
+ lst_rlt = next_values
43
+
44
+ ##########end上面可以改动
45
+ return lst_rlt
46
+
47
+ if __name__ == "__main__":
48
+ ###########下面可以修改
49
+ n, k = 3, 7
50
+ print(TEST_DO_NOT_CHANGE(n,k))
51
+ # 题号:hwc421
@@ -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
+ 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。
16
+ 数字到字母的映射如下(与电话按键相同):2→abc,3→def,4→ghi,5→jkl,
17
+ 6→mno,7→pqrs,8→tuv,9→wxyz。注意 1 不对应任何字母。
18
+
19
+ 示例:
20
+
21
+ 输入:"23"
22
+ 输出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
23
+ '''
24
+
25
+ # 参考答案
26
+
27
+ def TEST_DO_NOT_CHANGE(digits):
28
+ rlt = None
29
+ ##########start下面可以改动
30
+
31
+ from itertools import product
32
+
33
+ letters = {
34
+ "2": "abc", "3": "def", "4": "ghi", "5": "jkl",
35
+ "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz",
36
+ }
37
+ rlt = ["".join(chars) for chars in product(*(letters[digit] for digit in digits))] if digits else []
38
+
39
+ ##########end上面可以改动
40
+ return rlt
41
+
42
+ if __name__ == "__main__":
43
+ ###########下面可以修改
44
+ print(TEST_DO_NOT_CHANGE("23"))
45
+ print(TEST_DO_NOT_CHANGE("45"))
46
+ print(TEST_DO_NOT_CHANGE("47"))
47
+
48
+ # 题号:hwc424
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 参考同目录中的 hwc501.pdf(图 1 为题目所需图形)。
16
+
17
+
18
+ 使用 Python 语言并采用蒙特卡洛方法求 hwc501.pdf 图 1 中阴影部分的面积。
19
+ 请在报告中说明采样矩形的边界、阴影区域的判定条件,并使用 random.seed(2026) 固定随机种子。
20
+ import random
21
+ random.random() #返回[0.0,1)之间的浮点数
22
+ random.uniform(a, b)#返回[a,b]之间的浮点数
23
+ random.randint(a, b)#返回[a,b]之间的整数
24
+
25
+ 建议:至少产生 100000 个样本点;以样本比例乘采样矩形面积作为估计值,并给出误差阈值(建议绝对误差不超过 0.1)及验收标准。
26
+ '''
27
+
28
+ # 参考答案
29
+ def TEST_DO_NOT_CHANGE():
30
+ result = -1
31
+ ##########start下面可以改动
32
+
33
+ # 把图的左下角当作 (0, 0),在 [0, 20]×[0, 10] 内均匀采样。
34
+ # 两个圆的圆心为 (5, 5)、(15, 5),半径为 5。
35
+ # 阴影在 y <= x/2 且 x >= 5 的部分,两个圆的内部和左下角白色小块不计。
36
+ import random
37
+ from math import asin, pi
38
+
39
+ random.seed(2026)
40
+ samples = 1_000_000
41
+ hits = 0
42
+ for _ in range(samples):
43
+ x = random.uniform(0, 20)
44
+ y = random.uniform(0, 10)
45
+ if (x >= 5 and y <= x / 2
46
+ and (x - 5) ** 2 + (y - 5) ** 2 >= 25
47
+ and (x - 15) ** 2 + (y - 5) ** 2 >= 25):
48
+ hits += 1
49
+ result = 200 * hits / samples
50
+
51
+ # 对角线把“矩形减去两圆”按中心对称平分,单侧面积为 100 - 25π。
52
+ # 左下角白色小块的面积为 10 - 12.5 asin(3/5),由直线和左圆下弧分段积分得到。
53
+ # 因此解析值为 90 - 25π + 12.5 asin(3/5),单位为平方厘米。
54
+ # 验收标准是固定种子得到的估计值与解析值的绝对误差不超过 0.1。
55
+ exact = 90 - 25 * pi + 12.5 * asin(3 / 5)
56
+ assert abs(result - exact) <= 0.1
57
+
58
+ ##########end上面可以改动
59
+ return result
60
+
61
+ if __name__ == "__main__":
62
+ ###########下面可以修改
63
+ print(TEST_DO_NOT_CHANGE())
@@ -0,0 +1,69 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:小行星碰撞
15
+
16
+ 给定一个整数数组 asteroids,表示在同一行的小行星。
17
+ 对于该数组中的每一个元素,其绝对值表示小行星的大小,正负表示小行星的移动方向(正表示向右移动,负表示向左移动)。
18
+
19
+ 碰撞规则:
20
+ 1.每一颗小行星以相同的速度移动。
21
+ 2.两个小行星相互碰撞,较小的小行星会爆炸。
22
+ 3.如果两颗小行星大小相同,则两颗小行星都会爆炸。
23
+ 4.两颗移动方向相同的小行星,永远不会发生碰撞。
24
+
25
+ 请你找出碰撞后剩下的所有小行星。
26
+
27
+ 示例 1:
28
+
29
+ 输入:asteroids = [5,10,-5]
30
+ 输出:[5,10]
31
+ 解释:10 和 -5 碰撞后只剩下 10 。 5 和 10 永远不会发生碰撞。
32
+
33
+ 示例 2:
34
+
35
+ 输入:asteroids = [8,-8]
36
+ 输出:[]
37
+ 解释:8 和 -8 碰撞后,两者都发生爆炸。
38
+
39
+ 示例 3:
40
+
41
+ 输入:asteroids = [10,2,-5]
42
+ 输出:[10]
43
+ 解释:2 和 -5 发生碰撞后剩下 -5 。10 和 -5 发生碰撞后剩下 10 。
44
+ '''
45
+
46
+ # 参考答案
47
+ def TEST_DO_NOT_CHANGE(asteroids):
48
+ result=[]
49
+ ##########start下面可以改动
50
+
51
+ for asteroid in asteroids:
52
+ while result and result[-1] > 0 > asteroid:
53
+ if result[-1] < -asteroid:
54
+ result.pop()
55
+ continue
56
+ if result[-1] == -asteroid:
57
+ result.pop()
58
+ break
59
+ else:
60
+ result.append(asteroid)
61
+
62
+ ##########end上面可以改动
63
+ return result
64
+ if __name__ == "__main__":
65
+ ###########下面可以修改
66
+ print(TEST_DO_NOT_CHANGE([5,10,-5]))
67
+ print(TEST_DO_NOT_CHANGE([8,-8]))
68
+ print(TEST_DO_NOT_CHANGE([10,2,-5]))
69
+ # 题号:hwc502
@@ -0,0 +1,75 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+
16
+ 给你一个大小为 m x n 的二进制矩阵 grid 。
17
+ 岛屿 是由一些相邻的 1 (代表土地) 构成的组合,这里的「相邻」要求两个 1 必须在水平或者竖直的四个方向上相邻。
18
+ 你可以假设 grid 的四个边缘都被 0(代表水)包围着。
19
+ 岛屿的面积是岛上值为 1 的单元格的数目。请返回所有岛屿中的最大面积;若不存在岛屿,返回 0。
20
+
21
+
22
+
23
+ 示例 1:
24
+ 输入: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],
25
+ [0,0,0,0,0,0,0,1,1,1,0,0,0],
26
+ [0,1,1,0,1,0,0,0,0,0,0,0,0],
27
+ [0,1,0,0,1,1,0,0,1,0,1,0,0],
28
+ [0,1,0,0,1,1,0,0,1,1,1,0,0],
29
+ [0,0,0,0,0,0,0,0,0,0,1,0,0],
30
+ [0,0,0,0,0,0,0,1,1,1,0,0,0],
31
+ [0,0,0,0,0,0,0,1,1,0,0,0,0]]
32
+ 输出: 6
33
+ 解释: 答案不应该是 11 ,因为岛屿只能包含水平或垂直这四个方向上的 1 。
34
+
35
+ 示例 2:
36
+
37
+ 输入: grid = [[0,0,0,0,0,0,0,0]]
38
+ 输出: 0
39
+ '''
40
+
41
+ # 参考答案
42
+
43
+
44
+
45
+ def TEST_DO_NOT_CHANGE(grid):
46
+ rlt = None
47
+ ##########start下面可以改动
48
+
49
+ rlt = 0
50
+ visited = set()
51
+ for row, cells in enumerate(grid):
52
+ for col, value in enumerate(cells):
53
+ if value != 1 or (row, col) in visited:
54
+ continue
55
+ stack = [(row, col)]
56
+ visited.add((row, col))
57
+ area = 0
58
+ while stack:
59
+ r, c = stack.pop()
60
+ area += 1
61
+ for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
62
+ nr, nc = r + dr, c + dc
63
+ if (0 <= nr < len(grid) and 0 <= nc < len(grid[0])
64
+ and grid[nr][nc] == 1 and (nr, nc) not in visited):
65
+ visited.add((nr, nc))
66
+ stack.append((nr, nc))
67
+ rlt = max(rlt, area)
68
+
69
+ ##########end上面可以改动
70
+ return rlt
71
+
72
+ if __name__ == "__main__":
73
+ ###########下面可以修改
74
+ print(TEST_DO_NOT_CHANGE([[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]))
75
+ print(TEST_DO_NOT_CHANGE([[0,0,0,0,0,0,0,0]]))
@@ -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
+ 给定一个正整数,找出与其二进制表达式中1的个数相同且大小最接近的那两个数(一个略大,一个略小)。
16
+ 输出一个包含两个整数的列表。
17
+
18
+ 示例:
19
+ 输入:num = 2
20
+ 输出:[4, 1]
21
+ '''
22
+
23
+ # 参考答案
24
+
25
+ def TEST_DO_NOT_CHANGE(num):
26
+ lst_out = []
27
+ ##########start下面可以改动
28
+
29
+ # 头部补零,以便找到比输入位数更多的下一个数。
30
+ bits = "0" + format(num, "b")
31
+
32
+ def neighbor(pair):
33
+ pivot = bits.rfind(pair)
34
+ if pivot < 0:
35
+ return -1 # 不存在具有同样多的 1 的更小非负整数。
36
+ tail = bits[pivot + 2:]
37
+ ones = "1" * tail.count("1")
38
+ zeros = "0" * tail.count("0")
39
+ suffix = zeros + ones if pair == "01" else ones + zeros
40
+ return int(bits[:pivot] + pair[::-1] + suffix, 2)
41
+
42
+ lst_out = [neighbor("01"), neighbor("10")]
43
+
44
+ ##########end上面可以改动
45
+ return lst_out
46
+
47
+
48
+ if __name__ == "__main__":
49
+ ###########下面可以修改
50
+ num = 2
51
+ print(TEST_DO_NOT_CHANGE(num))
52
+ # 题号:hwc504
@@ -0,0 +1,63 @@
1
+ '''
2
+ 请只在 "
3
+ ##########start下面可以改动
4
+
5
+ ##########end上面可以改动 "
6
+
7
+ 中间部分作答,作答行数自由调整
8
+
9
+ 请不要使用 input() 函数
10
+
11
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
12
+
13
+ 题目:逆波兰表达式计算器
14
+
15
+ 逆波兰表达式是一种数学表达式的表示方法,其中操作符在操作数的后面。例如,表达式 2 + 3 的逆波兰表示法是 2 3 +。逆波兰表达式具有以下特点:
16
+
17
+ 逆波兰表达式不需要使用括号,因为操作符的位置已经明确表示了运算的优先级。
18
+ 逆波兰表达式可以直接由计算机进行计算,而无需解析表达式。
19
+ 编写一个 Python 程序,接受一个包含逆波兰表达式的字符串作为输入,计算并输出表达式的结果。
20
+
21
+ 编写一个函数 TEST_DO_NOT_CHANGE(expression),它接受一个逆波兰表达式字符串 expression 作为参数,返回表达式的计算结果。
22
+
23
+ 表达式只包含整数和 +、-、*、/ 四种二元运算符,记号之间以空格分隔;除法按真实数值计算,
24
+ 表达式保证合法且除数不为 0。若输入不符合上述语法,函数应抛出 ValueError。
25
+
26
+ 例如,如果输入字符串是 "2 3 +",程序应该返回 5,如果输入字符串是 "3 4 + 2 *",程序应该返回 14。
27
+ '''
28
+
29
+ # 参考答案
30
+
31
+ def TEST_DO_NOT_CHANGE(expression):
32
+ output=None
33
+ ##########start下面可以改动
34
+
35
+ import operator
36
+ import re
37
+
38
+ operations = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}
39
+ stack = []
40
+ for token in expression.split():
41
+ if token in operations:
42
+ if len(stack) < 2:
43
+ raise ValueError("运算符缺少操作数")
44
+ right, left = stack.pop(), stack.pop()
45
+ if token == "/" and right == 0:
46
+ raise ValueError("除数不能为零")
47
+ stack.append(operations[token](left, right))
48
+ elif re.fullmatch(r"[+-]?[0-9]+", token):
49
+ stack.append(int(token))
50
+ else:
51
+ raise ValueError(f"无效记号:{token}")
52
+ if len(stack) != 1:
53
+ raise ValueError("表达式必须恰好得到一个结果")
54
+ output = stack[0]
55
+
56
+ ##########end上面可以改动
57
+ return output
58
+
59
+
60
+ if __name__ == "__main__":
61
+ ###########下面可以修改
62
+ print(TEST_DO_NOT_CHANGE("2 3 +"))
63
+ print(TEST_DO_NOT_CHANGE("3 4 + 2 *"))
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:给你一个字符串 s,找到 s 中最长的回文子串。
15
+ 请注意,回文子串是指正着读和反着读都相同的字符串。
16
+ 如果存在多个等长的最长回文子串,返回其中任意一个即可。
17
+
18
+ 示例 1:
19
+
20
+ 输入:s = "babad"
21
+ 输出:"bab"
22
+ 解释:"aba" 同样是符合题意的答案。
23
+ 示例 2:
24
+
25
+ 输入:s = "cbbd"
26
+ 输出:"bb"
27
+ 示例 3:
28
+
29
+ 输入:s = "a"
30
+ 输出:"a"
31
+ 示例 4:
32
+
33
+ 输入:s = "ac"
34
+ 输出:"a"
35
+ '''
36
+
37
+ # 参考答案
38
+ def TEST_DO_NOT_CHANGE(s):
39
+ str_rlt = None
40
+ ##########start下面可以改动
41
+
42
+ def expand(left, right):
43
+ while left >= 0 and right < len(s) and s[left] == s[right]:
44
+ left -= 1
45
+ right += 1
46
+ return left + 1, right
47
+
48
+ best_start = best_end = 0
49
+ for i in range(len(s)):
50
+ for start, end in (expand(i, i), expand(i, i + 1)):
51
+ if end - start > best_end - best_start:
52
+ best_start, best_end = start, end
53
+ str_rlt = s[best_start:best_end]
54
+
55
+ ##########end上面可以改动
56
+ return str_rlt
57
+
58
+ if __name__ == "__main__":
59
+ ###########下面可以修改
60
+ s = "babad"
61
+ print(TEST_DO_NOT_CHANGE(s))
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+
16
+ 给定一个由 0 和 1 组成的矩阵 mat ,请输出一个大小相同的矩阵,
17
+ 其中每一个格子是 mat 中对应位置元素到最近的 0 的距离。两个相邻元素间的距离为 1 。
18
+
19
+
20
+ 示例 1:
21
+ 输入: mat = [[0,0,0],[0,1,0],[0,0,0]]
22
+ 输出: [[0,0,0],[0,1,0],[0,0,0]]
23
+
24
+ 示例 2:
25
+ 输入: mat = [[0,0,0],[0,1,0],[1,1,1]]
26
+ 输出: [[0,0,0],[0,1,0],[1,2,1]]
27
+ '''
28
+
29
+ # 参考答案
30
+
31
+ def TEST_DO_NOT_CHANGE(mat):
32
+ rlt = None
33
+ ##########start下面可以改动
34
+
35
+ from collections import deque
36
+
37
+ # 如果矩阵没有 0,则每个格子的距离均无定义,保留为 -1。
38
+ rlt = [[-1] * len(row) for row in mat]
39
+ queue = deque()
40
+ for r, row in enumerate(mat):
41
+ for c, value in enumerate(row):
42
+ if value == 0:
43
+ rlt[r][c] = 0
44
+ queue.append((r, c))
45
+ while queue:
46
+ row, col = queue.popleft()
47
+ for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
48
+ nr, nc = row + dr, col + dc
49
+ if 0 <= nr < len(mat) and 0 <= nc < len(mat[0]) and rlt[nr][nc] == -1:
50
+ rlt[nr][nc] = rlt[row][col] + 1
51
+ queue.append((nr, nc))
52
+
53
+ ##########end上面可以改动
54
+ return rlt
55
+
56
+ if __name__ == "__main__":
57
+ ###########下面可以修改
58
+ print(TEST_DO_NOT_CHANGE([[0,0,0],[0,1,0],[0,0,0]]))
59
+ print(TEST_DO_NOT_CHANGE([[0,0,0],[0,1,0],[1,1,1]]))
60
+ # 题号:hwc508
@@ -0,0 +1,85 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+
16
+ 在给定的网格中,每个单元格可以有以下三个值之一:
17
+
18
+
19
+ 值 0 代表空单元格;
20
+ 值 1 代表新鲜橘子;
21
+ 值 2 代表腐烂的橘子。
22
+ 每分钟,任何与腐烂的橘子(在 4 个正方向上)相邻的新鲜橘子都会腐烂。
23
+
24
+
25
+ 返回直到单元格中没有新鲜橘子为止所必须经过的最小分钟数。如果不可能,返回 -1
26
+
27
+
28
+
29
+
30
+
31
+ 示例 1:
32
+ 输入: [[2,1,1],[1,1,0],[0,1,1]]
33
+ 输出: 4
34
+
35
+ 示例 2:
36
+ 输入: [[2,1,1],[0,1,1],[1,0,1]]
37
+ 输出: -1
38
+ 解释: 左下角的橘子(零基坐标为第 2 行、第 0 列,即自然语言中的第 3 行第 1 列)永远不会腐烂,因为腐烂只会发生在 4 个正方向上。
39
+
40
+
41
+ 示例 3:
42
+ 输入: [[0,2]]
43
+ 输出: 0
44
+ 解释: 因为 0 分钟时已经没有新鲜橘子了,所以答案就是 0 。
45
+ '''
46
+
47
+ # 参考答案
48
+
49
+
50
+
51
+ def TEST_DO_NOT_CHANGE(nums):
52
+ rlt = None
53
+ ##########start下面可以改动
54
+
55
+ from collections import deque
56
+
57
+ fresh = set()
58
+ queue = deque()
59
+ for row, cells in enumerate(nums):
60
+ for col, value in enumerate(cells):
61
+ if value == 1:
62
+ fresh.add((row, col))
63
+ elif value == 2:
64
+ queue.append((row, col, 0))
65
+ rlt = 0
66
+ while queue and fresh:
67
+ row, col, minutes = queue.popleft()
68
+ for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
69
+ neighbor = row + dr, col + dc
70
+ if neighbor in fresh:
71
+ fresh.remove(neighbor)
72
+ rlt = minutes + 1
73
+ queue.append((*neighbor, rlt))
74
+ if fresh:
75
+ rlt = -1
76
+
77
+ ##########end上面可以改动
78
+ return rlt
79
+
80
+ if __name__ == "__main__":
81
+ ###########下面可以修改
82
+ print(TEST_DO_NOT_CHANGE([[2,1,1],[1,1,0],[0,1,1]]))
83
+ print(TEST_DO_NOT_CHANGE([[2,1,1],[0,1,1],[1,0,1]]))
84
+ print(TEST_DO_NOT_CHANGE([[0,2]]))
85
+ # 题号:hwc509