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,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给定一个大小为 n 的整数数组,找出其中所有出现次数 超过三分之一(大于 ⌊n/3⌋,即 n 除以 3 向下取整)的元素。
16
+
17
+ 进阶(可选):尝试只把数组遍历一遍、几乎不使用额外空间解决此问题。
18
+
19
+ 示例 1:
20
+ 输入: [3,2,3]
21
+ 输出: [3]
22
+
23
+ 示例 2:
24
+ 输入: nums = [1]
25
+ 输出: [1]
26
+
27
+ 示例 3:
28
+ 输入: [1,1,1,3,3,2,2,2]
29
+ 输出: [1,2]
30
+ '''
31
+
32
+ # 参考答案
33
+ def TEST_DO_NOT_CHANGE(nums):
34
+ res = []
35
+ ##########start下面可以改动
36
+
37
+ from collections import Counter
38
+
39
+ res = [value for value, count in Counter(nums).items() if count > len(nums) // 3]
40
+
41
+ ##########end上面可以改动
42
+ return res
43
+
44
+ if __name__ == '__main__':
45
+ ###########下面可以修改
46
+ print(TEST_DO_NOT_CHANGE([3,2,3]))
47
+ print(TEST_DO_NOT_CHANGE([1]))
48
+ print(TEST_DO_NOT_CHANGE([1,1,1,3,3,2,2,2]))
49
+ # 题号:hwc314
@@ -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
+ 请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。
16
+ 例如矩阵matrix = [ [ 1, 2, 3 ],
17
+ [ 4, 5, 6 ],
18
+ [ 7, 8, 9 ]
19
+ ],返回的结果为[1, 2, 3, 6, 9, 8, 7, 4, 5]
20
+ 请按照顺时针螺旋顺序 ,返回以下矩阵中的所有元素。
21
+ matrix1 = [[2,3,1,4],[4,5,1,5],[1,7,4,9],[4,7,2,1]]
22
+ matrix2 = [[4,6,8],[1,8,5],[5,1,7]]
23
+ matrix3 = [[23,17,54,66],[22,77,34,79]]
24
+ '''
25
+
26
+ # 参考答案
27
+
28
+ def TEST_DO_NOT_CHANGE(matrix):
29
+ result = None
30
+ print(matrix)
31
+ ##########start下面可以改动
32
+
33
+ result = []
34
+ if not matrix or not matrix[0]:
35
+ return result
36
+ top, bottom = 0, len(matrix) - 1
37
+ left, right = 0, len(matrix[0]) - 1
38
+ while top <= bottom and left <= right:
39
+ result.extend(matrix[top][left:right + 1])
40
+ top += 1
41
+ for row in range(top, bottom + 1):
42
+ result.append(matrix[row][right])
43
+ right -= 1
44
+ if top <= bottom and left <= right:
45
+ result.extend(reversed(matrix[bottom][left:right + 1]))
46
+ bottom -= 1
47
+ if top <= bottom and left <= right:
48
+ for row in range(bottom, top - 1, -1):
49
+ result.append(matrix[row][left])
50
+ left += 1
51
+
52
+ ##########end上面可以改动
53
+ return result
54
+
55
+ if __name__ == "__main__":
56
+ ###########下面可以修改
57
+ matrix1 = [[2,3,1,4],[4,5,1,5],[1,7,4,9],[4,7,2,1]]
58
+ matrix2 = [[4,6,8],[1,8,5],[5,1,7]]
59
+ matrix3 = [[23,17,54,66],[22,77,34,79]]
60
+ print(TEST_DO_NOT_CHANGE(matrix1))
61
+ print(TEST_DO_NOT_CHANGE(matrix2))
62
+ print(TEST_DO_NOT_CHANGE(matrix3))
63
+ # 题号:hwc315
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目《统计优美子数组》
15
+
16
+ 问题描述
17
+ 给你一个整数数组 nums 和一个整数 k。如果某个连续子数组中恰好有 k 个奇数数字,我们就认为这个子数组是「优美子数组」。
18
+
19
+ 请返回这个数组中 「优美子数组」 的数目。
20
+
21
+
22
+
23
+ 示例 1:
24
+
25
+ 输入:nums = [1,1,2,1,1], k = 3
26
+ 输出:2
27
+ 解释:包含 3 个奇数的子数组是 [1,1,2,1] 和 [1,2,1,1] 。
28
+
29
+ 示例 2:
30
+
31
+ 输入:nums = [2,4,6], k = 1
32
+ 输出:0
33
+ 解释:数列中不包含任何奇数,所以不存在优美子数组。
34
+
35
+ 示例 3:
36
+
37
+ 输入:nums = [2,2,2,1,2,2,1,2,2,2], k = 2
38
+ 输出:16
39
+ '''
40
+
41
+ # 参考答案
42
+
43
+ def TEST_DO_NOT_CHANGE(nums,k):
44
+ print(nums)
45
+ rlt = None
46
+ ##########start下面可以改动
47
+
48
+ prefix_counts = {0: 1}
49
+ odd_count = rlt = 0
50
+ for value in nums:
51
+ odd_count += value % 2
52
+ rlt += prefix_counts.get(odd_count - k, 0)
53
+ prefix_counts[odd_count] = prefix_counts.get(odd_count, 0) + 1
54
+
55
+ ##########end上面可以改动
56
+ return rlt
57
+
58
+
59
+ if __name__ == "__main__":
60
+ ###########下面可以修改
61
+ print(TEST_DO_NOT_CHANGE([1,1,2,1,1],3))
62
+ print(TEST_DO_NOT_CHANGE([2,4,6],1))
63
+ print(TEST_DO_NOT_CHANGE([2,2,2,1,2,2,1,2,2,2],2))
64
+
65
+ # 题号:hwc316
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:插入后的最大值
15
+ 给你一个非常大的整数n和一个整数数字x,大整数n用一个字符串表示。n中每一位数字和数字x都处于闭区间 [1, 9] 中,且 n 可能表示一个 负数 。
16
+ 你打算通过在n的十进制表示的任意位置插入x来最大化n的数值​​​​​,但不能在负号的左边插入x。
17
+ 例如,如果n = 73且x = 6,那么最佳方案是将6插入7和3之间,使n = 763。
18
+ 如果n = -55且x = 2,那么最佳方案是将2插在第一个5之前,使n = -255。
19
+ 返回插入操作后,用字符串表示的n的最大值。
20
+
21
+ 示例:
22
+ 输入:n = "99", x = 9
23
+ 输出:"999"解释:不管在哪里插入 9 ,结果都是相同的。
24
+
25
+ 提示:
26
+ 1 <= n.length <= 105
27
+ 1 <= x <= 9
28
+ n​​​中每一位的数字都在闭区间[1, 9]中。
29
+ n代表一个有效的整数。
30
+ 当n表示负数时,将会以字符'-'开始。
31
+ '''
32
+
33
+ # 参考答案
34
+
35
+ def TEST_DO_NOT_CHANGE(n, x):
36
+ print(n, x)
37
+ lst_rlt =None
38
+ ##########start下面可以改动
39
+
40
+ digit = str(x)
41
+ negative = n.startswith("-")
42
+ i = int(negative)
43
+ while i < len(n):
44
+ if (negative and digit < n[i]) or (not negative and digit > n[i]):
45
+ break
46
+ i += 1
47
+ lst_rlt = n[:i] + digit + n[i:]
48
+
49
+ ##########end上面可以改动
50
+ return lst_rlt
51
+
52
+ if __name__ == "__main__":
53
+ ###########下面可以修改
54
+ n = "99"
55
+ x = 9
56
+ print(TEST_DO_NOT_CHANGE(n,x))
57
+ # 题号:hwc317
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目
15
+ 给你一个整数 n ,请你找出并返回第 n 个 丑数 。
16
+
17
+ 丑数 就是只包含质因数 2、3、5 的正整数(换句话说:把它不断地除以 2、3、5,最后能正好除尽变成 1;注意 1 也算丑数)。
18
+
19
+
20
+
21
+ 示例 1:
22
+ 输入:n = 10
23
+ 输出:12
24
+ 解释:[1, 2, 3, 4, 5, 6, 8, 9, 10, 12] 是由前 10 个丑数组成的序列。
25
+
26
+ 示例 2:
27
+ 输入:n = 1
28
+ 输出:1
29
+ 解释:1 通常被视为丑数。
30
+ '''
31
+
32
+ # 参考答案
33
+
34
+ def TEST_DO_NOT_CHANGE(n):
35
+ rlt = None
36
+ ##########start下面可以改动
37
+
38
+ ugly = [1]
39
+ i = j = k = 0
40
+ while len(ugly) < n:
41
+ next_two, next_three, next_five = 2 * ugly[i], 3 * ugly[j], 5 * ugly[k]
42
+ value = min(next_two, next_three, next_five)
43
+ ugly.append(value)
44
+ i += value == next_two
45
+ j += value == next_three
46
+ k += value == next_five
47
+ rlt = ugly[-1]
48
+
49
+ ##########end上面可以改动
50
+ return rlt
51
+
52
+ if __name__ == "__main__":
53
+ ###########下面可以修改
54
+ print(TEST_DO_NOT_CHANGE(10))
55
+ print(TEST_DO_NOT_CHANGE(5))
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:字符串压缩。
15
+ 利用字符重复出现的次数,编写一种方法,实现基本的字符串压缩功能。
16
+ 比如,字符串aabcccccaaa会变为a2b1c5a3。若“压缩”后的字符串没有变短,则返回原先的字符串。
17
+ 你可以假设字符串中只包含大小写英文字母(A-Z、a-z)。
18
+
19
+ 示例1:
20
+
21
+ 输入:"aabcccccaaa"
22
+ 输出:"a2b1c5a3"
23
+ 示例2:
24
+
25
+ 输入:"abbccd"
26
+ 输出:"abbccd"
27
+ 解释:"abbccd"压缩后为"a1b2c2d1",比原字符串长度更长。
28
+ 提示:
29
+ '''
30
+
31
+ # 参考答案
32
+ def TEST_DO_NOT_CHANGE(s1):
33
+ print(s1)
34
+ str_rlt = None
35
+ ##########start下面可以改动
36
+
37
+ from itertools import groupby
38
+
39
+ compressed = "".join(f"{char}{sum(1 for _ in group)}" for char, group in groupby(s1))
40
+ str_rlt = compressed if len(compressed) < len(s1) else s1
41
+
42
+ ##########end上面可以改动
43
+ return str_rlt
44
+
45
+
46
+ if __name__ == "__main__":
47
+ ###########下面可以修改
48
+ s1 = "aabcccccaaa"
49
+ print(TEST_DO_NOT_CHANGE(s1))
50
+ print(TEST_DO_NOT_CHANGE("abbccd"))
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:(改编自计算机二级 Python 真题·综合应用题·字符串处理考点)
15
+ 将一个 0~999 之间的非负整数 n 转换成英文单词字符串返回。
16
+ 要求使用递归实现,参数为整数 n,返回一个英文单词字符串。
17
+ 字典:0→zero, 1→one, 2→two, 3→three, 4→four, 5→five,
18
+ 6→six, 7→seven, 8→eight, 9→nine, 10→ten,
19
+ 11→eleven, 12→twelve, 13→thirteen, 14→fourteen,
20
+ 15→fifteen, 16→sixteen, 17→seventeen, 18→eighteen, 19→nineteen,
21
+ 20→twenty, 30→thirty, 40→forty, 50→fifty, 60→sixty, 70→seventy,
22
+ 80→eighty, 90→ninety
23
+
24
+ 提示:小于 20 直接查表;20-99 之间用 "tens + units";100-999 用
25
+ "X hundred [ + Y ]"(Y=0 时不加 and/Y)。
26
+
27
+ 示例:
28
+ 输入:n = 0
29
+ 输出:"zero"
30
+
31
+ 输入:n = 5
32
+ 输出:"five"
33
+
34
+ 输入:n = 23
35
+ 输出:"twenty three"
36
+
37
+ 输入:n = 100
38
+ 输出:"one hundred"
39
+
40
+ 输入:n = 115
41
+ 输出:"one hundred fifteen"
42
+
43
+ 输入:n = 999
44
+ 输出:"nine hundred ninety nine"
45
+ '''
46
+
47
+ # 参考答案
48
+
49
+ def TEST_DO_NOT_CHANGE(n):
50
+ rlt = None
51
+ ##########start下面可以改动
52
+
53
+ small = (
54
+ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
55
+ "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
56
+ "sixteen", "seventeen", "eighteen", "nineteen",
57
+ )
58
+ tens = ("", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
59
+
60
+ def english(value):
61
+ if value < 20:
62
+ return small[value]
63
+ if value < 100:
64
+ quotient, remainder = divmod(value, 10)
65
+ prefix = tens[quotient]
66
+ else:
67
+ quotient, remainder = divmod(value, 100)
68
+ prefix = english(quotient) + " hundred"
69
+ return prefix + (" " + english(remainder) if remainder else "")
70
+
71
+ rlt = english(n)
72
+
73
+ ##########end上面可以改动
74
+ return rlt
75
+
76
+ if __name__ == "__main__":
77
+ ###########下面可以修改
78
+ print(TEST_DO_NOT_CHANGE(0))
79
+ print(TEST_DO_NOT_CHANGE(5))
80
+ print(TEST_DO_NOT_CHANGE(23))
81
+ print(TEST_DO_NOT_CHANGE(100))
82
+ print(TEST_DO_NOT_CHANGE(115))
83
+ print(TEST_DO_NOT_CHANGE(999))
84
+ # 题号:hwc320
@@ -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
+ 给定一个整数数组 nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次。
16
+ 找出只出现一次的那两个元素。你可以按任意顺序返回答案。
17
+
18
+ 示例 1:
19
+ 输入:nums = [1,2,1,3,2,5]
20
+ 输出:[3,5]
21
+ 解释:[5, 3] 也是有效的答案。
22
+
23
+ 示例 2:
24
+ 输入:nums = [-1,0]
25
+ 输出:[-1,0]
26
+
27
+ 示例 3:
28
+ 输入:nums = [0,1]
29
+ 输出:[1,0]
30
+ '''
31
+
32
+ # 参考答案
33
+ def TEST_DO_NOT_CHANGE(nums):
34
+ single_numbers = None
35
+ ##########start下面可以改动
36
+
37
+ from collections import Counter
38
+
39
+ single_numbers = [value for value, count in Counter(nums).items() if count == 1]
40
+
41
+ ##########end上面可以改动
42
+ return single_numbers
43
+
44
+ if __name__ == "__main__":
45
+ ###########下面可以修改
46
+ print(TEST_DO_NOT_CHANGE([1,2,1,3,2,5]))
47
+ print(TEST_DO_NOT_CHANGE([-1,0]))
48
+ print(TEST_DO_NOT_CHANGE([0,1]))
49
+ # 题号:hwc321
@@ -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
+ 已知m*n矩阵matrix,将该矩阵顺时针旋转90度,并输出新矩阵。
16
+ 示例:
17
+ matrix = [
18
+ [1, 2, 3],
19
+ [4, 5, 6],
20
+ [7, 8, 9]
21
+ ]
22
+ 正确输出结果为:
23
+ matrix_90 = [[7, 4, 1],[8, 5, 2],[9, 6, 3]]
24
+
25
+ 请将以下矩阵顺时针旋转90度,并输出结果。
26
+ matrix1 = [[2,3,1,4],[4,5,1,5],[1,7,4,9],[4,7,2,1]]
27
+ matrix2 = [[4,6,8],[1,8,5],[5,1,7]]
28
+ matrix3 = [[23,17,54,66],[22,77,34,79]]
29
+ '''
30
+
31
+ # 参考答案
32
+ def TEST_DO_NOT_CHANGE(matrix):
33
+ result=None
34
+ ##########start下面可以改动
35
+
36
+ result = [list(column) for column in zip(*reversed(matrix))]
37
+
38
+ ##########end上面可以改动
39
+ return result
40
+
41
+ if __name__ == "__main__":
42
+ ###########下面可以修改
43
+ matrix1 = [[2,3,1,4],[4,5,1,5],[1,7,4,9],[4,7,2,1]]
44
+ matrix2 = [[4,6,8],[1,8,5],[5,1,7]]
45
+ matrix3 = [[23,17,54,66],[22,77,34,79]]
46
+
47
+ print(TEST_DO_NOT_CHANGE(matrix1))
48
+ print(TEST_DO_NOT_CHANGE(matrix2))
49
+ print(TEST_DO_NOT_CHANGE(matrix3))
@@ -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
+ 给定整数数组 nums,判断 nums 中是否存在三个元素 a, b, c,使得 a + b + c = 0?
16
+ 找出所有满足条件且不重复的三元组,返回一个列表,列表内每个元素是长度为 3 的 list。
17
+ 三元组内部 a、b、c 按非降序排列;返回列表按字典序排列。
18
+
19
+ 例如:
20
+ nums = [-1, 0, 1, 2, -1, -4, 4, -3, 7, -5]
21
+ result 形式如下:
22
+ [[-5, 1, 4], [-4, -3, 7], [-4, 0, 4], [-3, -1, 4], [-3, 1, 2], [-1, -1, 2], [-1, 0, 1]]
23
+ 现有如下几个数组:
24
+ nums1 = [-1, 0, 1, 2, -1, -4, 3]
25
+ nums2 = [-2, 0, 1, 1, -1, 3, 4]
26
+ nums3 = [0, -1, 2, -3, 1, 2, 4]
27
+ '''
28
+
29
+ # 参考答案
30
+
31
+ def TEST_DO_NOT_CHANGE(nums):
32
+ print(nums)
33
+ result = []
34
+ ##########start下面可以改动
35
+
36
+ values = sorted(nums)
37
+ for i in range(len(values) - 2):
38
+ first = values[i]
39
+ if first > 0:
40
+ break
41
+ if i > 0 and first == values[i - 1]:
42
+ continue
43
+ left, right = i + 1, len(values) - 1
44
+ while left < right:
45
+ total = first + values[left] + values[right]
46
+ if total < 0:
47
+ left += 1
48
+ elif total > 0:
49
+ right -= 1
50
+ else:
51
+ result.append([first, values[left], values[right]])
52
+ left += 1
53
+ right -= 1
54
+ while left < right and values[left] == values[left - 1]:
55
+ left += 1
56
+ while left < right and values[right] == values[right + 1]:
57
+ right -= 1
58
+
59
+ ##########end上面可以改动
60
+ return result
61
+
62
+ if __name__ == "__main__":
63
+ ###########下面可以修改
64
+ nums1 = [-1, 0, 1, 2, -1, -4, 3]
65
+ nums2 = [-2, 0, 1, 1, -1, 3, 4]
66
+ nums3 = [0, -1, 2, -3, 1, 2, 4]
67
+ print(TEST_DO_NOT_CHANGE(nums1))
68
+ print(TEST_DO_NOT_CHANGE(nums2))
69
+ print(TEST_DO_NOT_CHANGE(nums3))
@@ -0,0 +1,66 @@
1
+ '''
2
+ 请只在 "
3
+ ##########start下面可以改动
4
+
5
+ ##########end上面可以改动 "
6
+
7
+ 中间部分作答,作答行数自由调整
8
+
9
+ 请不要使用 input() 函数
10
+
11
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
12
+
13
+ 题目:最长递增子序列
14
+
15
+ 给你一个整数列表 arr,请找到其中最长递增子序列的长度。
16
+
17
+ 子序列是由原列表派生而来的序列:删除(或不删除)列表中的一些元素,且不改变其余元素的相对顺序。
18
+ 注意:子序列不要求元素在原列表中连续,但必须保持原有的先后顺序;本题中的"递增"指严格递增,即后一个元素必须严格大于前一个元素。
19
+
20
+ 示例 1:
21
+
22
+ 输入:arr = [10, 22, 9, 33, 21, 50, 41, 60, 80]
23
+ 输出:6
24
+ 解释:最长递增子序列是 [10, 22, 33, 50, 60, 80],长度为 6。
25
+
26
+ 示例 2:
27
+
28
+ 输入:arr = [3, 10, 2, 1, 20]
29
+ 输出:3
30
+ 解释:最长递增子序列是 [3, 10, 20],长度为 3。
31
+
32
+ 示例 3:
33
+
34
+ 输入:arr = [7, 7, 7, 7]
35
+ 输出:1
36
+ 解释:所有元素相等,不存在长度大于 1 的严格递增子序列。
37
+
38
+ 提示:
39
+ 如果 arr 为空列表,函数应返回 0。
40
+
41
+ 请编写函数 TEST_DO_NOT_CHANGE(arr),其中 arr 是输入的整数列表,函数应该返回最长递增子序列的长度。
42
+ '''
43
+
44
+ # 参考答案
45
+ def TEST_DO_NOT_CHANGE(arr):
46
+ max_length = 0
47
+ #########start下面可以改动
48
+
49
+ from bisect import bisect_left
50
+
51
+ tails = []
52
+ for value in arr:
53
+ i = bisect_left(tails, value)
54
+ if i == len(tails):
55
+ tails.append(value)
56
+ else:
57
+ tails[i] = value
58
+ max_length = len(tails)
59
+
60
+ ##########end上面可以改动
61
+ return max_length
62
+
63
+ if __name__ == "__main__":
64
+ ###########下面可以修改
65
+ arr = [10, 22, 9, 33, 21, 50, 41, 60, 80]
66
+ print(TEST_DO_NOT_CHANGE(arr)) # 应该输出 6