From 64c9075950bef06b8c5a9a6cfd68c3424f51d776 Mon Sep 17 00:00:00 2001 From: zhangzc Date: Tue, 23 Nov 2021 11:09:38 +0800 Subject: [PATCH] test --- data/cpp/test.md | 0 data_backup/cpp_code_json/0.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/1.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/10.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/100.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/101.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/102.json | 17 +++++++++++++++++ data_backup/cpp_code_json/103.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/104.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/105.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/106.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/107.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/108.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/109.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/11.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/110.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/111.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/112.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/113.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/114.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/115.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/116.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/117.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/118.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/119.json | 17 +++++++++++++++++ data_backup/cpp_code_json/12.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/120.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/121.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/122.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/123.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/124.json | 17 +++++++++++++++++ data_backup/cpp_code_json/125.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/126.json | 17 +++++++++++++++++ data_backup/cpp_code_json/127.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/128.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/129.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/13.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/130.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/131.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/132.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/133.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/134.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/135.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/136.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/137.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/138.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/139.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/14.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/140.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/141.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/142.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/143.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/144.json | 17 +++++++++++++++++ data_backup/cpp_code_json/15.json | 17 +++++++++++++++++ data_backup/cpp_code_json/16.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/17.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/18.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/19.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/2.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/20.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/21.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/22.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/23.json | 17 +++++++++++++++++ data_backup/cpp_code_json/24.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/25.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/26.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/27.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/28.json | 17 +++++++++++++++++ data_backup/cpp_code_json/29.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/3.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/30.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/31.json | 17 +++++++++++++++++ data_backup/cpp_code_json/32.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/33.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/34.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/35.json | 17 +++++++++++++++++ data_backup/cpp_code_json/36.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/37.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/38.json | 17 +++++++++++++++++ data_backup/cpp_code_json/39.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/4.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/40.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/41.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/42.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/43.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/44.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/45.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/46.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/47.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/48.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/49.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/5.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/50.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/51.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/52.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/53.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/54.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/55.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/56.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/57.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/58.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/59.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/6.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/60.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/61.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/62.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/63.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/64.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/65.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/66.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/67.json | 17 +++++++++++++++++ data_backup/cpp_code_json/68.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/69.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/7.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/70.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/71.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/72.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/73.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/74.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/75.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/76.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/77.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/78.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/79.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/8.json | 17 +++++++++++++++++ data_backup/cpp_code_json/80.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/81.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/82.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/83.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/84.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/85.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/86.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/87.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/88.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/89.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/9.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/90.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/91.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/92.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/93.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/94.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/95.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/96.json | 17 +++++++++++++++++ data_backup/cpp_code_json/97.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/98.json | 18 ++++++++++++++++++ data_backup/cpp_code_json/99.json | 18 ++++++++++++++++++ data_backup/java_code_json/0.json | 18 ++++++++++++++++++ data_backup/java_code_json/1.json | 18 ++++++++++++++++++ data_backup/java_code_json/10.json | 18 ++++++++++++++++++ data_backup/java_code_json/11.json | 18 ++++++++++++++++++ data_backup/java_code_json/12.json | 18 ++++++++++++++++++ data_backup/java_code_json/13.json | 18 ++++++++++++++++++ data_backup/java_code_json/14.json | 18 ++++++++++++++++++ data_backup/java_code_json/15.json | 18 ++++++++++++++++++ data_backup/java_code_json/16.json | 18 ++++++++++++++++++ data_backup/java_code_json/17.json | 18 ++++++++++++++++++ data_backup/java_code_json/18.json | 18 ++++++++++++++++++ data_backup/java_code_json/19.json | 17 +++++++++++++++++ data_backup/java_code_json/2.json | 18 ++++++++++++++++++ data_backup/java_code_json/20.json | 18 ++++++++++++++++++ data_backup/java_code_json/21.json | 17 +++++++++++++++++ data_backup/java_code_json/22.json | 18 ++++++++++++++++++ data_backup/java_code_json/23.json | 18 ++++++++++++++++++ data_backup/java_code_json/24.json | 18 ++++++++++++++++++ data_backup/java_code_json/25.json | 18 ++++++++++++++++++ data_backup/java_code_json/26.json | 17 +++++++++++++++++ data_backup/java_code_json/27.json | 18 ++++++++++++++++++ data_backup/java_code_json/28.json | 18 ++++++++++++++++++ data_backup/java_code_json/29.json | 18 ++++++++++++++++++ data_backup/java_code_json/3.json | 17 +++++++++++++++++ data_backup/java_code_json/30.json | 18 ++++++++++++++++++ data_backup/java_code_json/31.json | 18 ++++++++++++++++++ data_backup/java_code_json/32.json | 18 ++++++++++++++++++ data_backup/java_code_json/33.json | 18 ++++++++++++++++++ data_backup/java_code_json/34.json | 18 ++++++++++++++++++ data_backup/java_code_json/35.json | 18 ++++++++++++++++++ data_backup/java_code_json/36.json | 18 ++++++++++++++++++ data_backup/java_code_json/37.json | 17 +++++++++++++++++ data_backup/java_code_json/38.json | 17 +++++++++++++++++ data_backup/java_code_json/39.json | 18 ++++++++++++++++++ data_backup/java_code_json/4.json | 18 ++++++++++++++++++ data_backup/java_code_json/40.json | 18 ++++++++++++++++++ data_backup/java_code_json/41.json | 17 +++++++++++++++++ data_backup/java_code_json/42.json | 18 ++++++++++++++++++ data_backup/java_code_json/43.json | 18 ++++++++++++++++++ data_backup/java_code_json/44.json | 18 ++++++++++++++++++ data_backup/java_code_json/45.json | 18 ++++++++++++++++++ data_backup/java_code_json/46.json | 18 ++++++++++++++++++ data_backup/java_code_json/47.json | 17 +++++++++++++++++ data_backup/java_code_json/48.json | 17 +++++++++++++++++ data_backup/java_code_json/49.json | 18 ++++++++++++++++++ data_backup/java_code_json/5.json | 18 ++++++++++++++++++ data_backup/java_code_json/50.json | 18 ++++++++++++++++++ data_backup/java_code_json/6.json | 17 +++++++++++++++++ data_backup/java_code_json/7.json | 18 ++++++++++++++++++ data_backup/java_code_json/8.json | 18 ++++++++++++++++++ data_backup/java_code_json/9.json | 18 ++++++++++++++++++ data_backup/leetcode/0.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/1.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/10.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/11.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/12.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/13.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/14.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/15.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/16.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/17.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/18.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/19.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/2.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/20.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/21.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/22.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/23.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/24.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/25.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/26.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/27.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/28.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/29.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/3.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/30.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/31.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/32.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/33.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/34.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/35.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/36.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/37.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/38.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/39.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/4.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/40.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/41.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/42.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/43.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/44.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/45.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/46.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/47.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/48.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/49.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/5.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/50.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/51.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/52.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/53.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/54.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/55.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/56.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/57.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/58.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/59.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/6.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/60.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/61.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/62.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/63.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/64.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/65.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/66.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/67.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/68.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/69.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/7.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/70.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/71.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/72.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/73.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/74.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/75.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/76.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/77.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/78.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/79.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/8.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/80.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/81.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/82.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/83.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/84.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/85.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/86.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/87.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/88.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/89.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/9.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/90.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/91.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/92.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/93.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/94.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/95.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/96.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/97.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/98.json | 24 ++++++++++++++++++++++++ data_backup/leetcode/99.json | 24 ++++++++++++++++++++++++ data_backup/python_code_json/0.json | 18 ++++++++++++++++++ data_backup/python_code_json/1.json | 18 ++++++++++++++++++ data_backup/python_code_json/10.json | 18 ++++++++++++++++++ data_backup/python_code_json/11.json | 18 ++++++++++++++++++ data_backup/python_code_json/12.json | 18 ++++++++++++++++++ data_backup/python_code_json/13.json | 17 +++++++++++++++++ data_backup/python_code_json/14.json | 17 +++++++++++++++++ data_backup/python_code_json/15.json | 17 +++++++++++++++++ data_backup/python_code_json/16.json | 17 +++++++++++++++++ data_backup/python_code_json/17.json | 17 +++++++++++++++++ data_backup/python_code_json/18.json | 18 ++++++++++++++++++ data_backup/python_code_json/19.json | 18 ++++++++++++++++++ data_backup/python_code_json/2.json | 17 +++++++++++++++++ data_backup/python_code_json/20.json | 18 ++++++++++++++++++ data_backup/python_code_json/21.json | 18 ++++++++++++++++++ data_backup/python_code_json/22.json | 18 ++++++++++++++++++ data_backup/python_code_json/23.json | 17 +++++++++++++++++ data_backup/python_code_json/24.json | 17 +++++++++++++++++ data_backup/python_code_json/25.json | 18 ++++++++++++++++++ data_backup/python_code_json/26.json | 17 +++++++++++++++++ data_backup/python_code_json/27.json | 18 ++++++++++++++++++ data_backup/python_code_json/28.json | 17 +++++++++++++++++ data_backup/python_code_json/29.json | 18 ++++++++++++++++++ data_backup/python_code_json/3.json | 17 +++++++++++++++++ data_backup/python_code_json/30.json | 18 ++++++++++++++++++ data_backup/python_code_json/31.json | 18 ++++++++++++++++++ data_backup/python_code_json/32.json | 18 ++++++++++++++++++ data_backup/python_code_json/33.json | 18 ++++++++++++++++++ data_backup/python_code_json/34.json | 17 +++++++++++++++++ data_backup/python_code_json/35.json | 18 ++++++++++++++++++ data_backup/python_code_json/36.json | 18 ++++++++++++++++++ data_backup/python_code_json/37.json | 18 ++++++++++++++++++ data_backup/python_code_json/38.json | 17 +++++++++++++++++ data_backup/python_code_json/39.json | 18 ++++++++++++++++++ data_backup/python_code_json/4.json | 18 ++++++++++++++++++ data_backup/python_code_json/40.json | 18 ++++++++++++++++++ data_backup/python_code_json/41.json | 18 ++++++++++++++++++ data_backup/python_code_json/42.json | 17 +++++++++++++++++ data_backup/python_code_json/43.json | 18 ++++++++++++++++++ data_backup/python_code_json/44.json | 18 ++++++++++++++++++ data_backup/python_code_json/45.json | 18 ++++++++++++++++++ data_backup/python_code_json/46.json | 18 ++++++++++++++++++ data_backup/python_code_json/47.json | 18 ++++++++++++++++++ data_backup/python_code_json/48.json | 18 ++++++++++++++++++ data_backup/python_code_json/49.json | 18 ++++++++++++++++++ data_backup/python_code_json/5.json | 17 +++++++++++++++++ data_backup/python_code_json/50.json | 18 ++++++++++++++++++ data_backup/python_code_json/6.json | 17 +++++++++++++++++ data_backup/python_code_json/7.json | 18 ++++++++++++++++++ data_backup/python_code_json/8.json | 18 ++++++++++++++++++ data_backup/python_code_json/9.json | 18 ++++++++++++++++++ 348 files changed, 6806 insertions(+) create mode 100644 data/cpp/test.md create mode 100644 data_backup/cpp_code_json/0.json create mode 100644 data_backup/cpp_code_json/1.json create mode 100644 data_backup/cpp_code_json/10.json create mode 100644 data_backup/cpp_code_json/100.json create mode 100644 data_backup/cpp_code_json/101.json create mode 100644 data_backup/cpp_code_json/102.json create mode 100644 data_backup/cpp_code_json/103.json create mode 100644 data_backup/cpp_code_json/104.json create mode 100644 data_backup/cpp_code_json/105.json create mode 100644 data_backup/cpp_code_json/106.json create mode 100644 data_backup/cpp_code_json/107.json create mode 100644 data_backup/cpp_code_json/108.json create mode 100644 data_backup/cpp_code_json/109.json create mode 100644 data_backup/cpp_code_json/11.json create mode 100644 data_backup/cpp_code_json/110.json create mode 100644 data_backup/cpp_code_json/111.json create mode 100644 data_backup/cpp_code_json/112.json create mode 100644 data_backup/cpp_code_json/113.json create mode 100644 data_backup/cpp_code_json/114.json create mode 100644 data_backup/cpp_code_json/115.json create mode 100644 data_backup/cpp_code_json/116.json create mode 100644 data_backup/cpp_code_json/117.json create mode 100644 data_backup/cpp_code_json/118.json create mode 100644 data_backup/cpp_code_json/119.json create mode 100644 data_backup/cpp_code_json/12.json create mode 100644 data_backup/cpp_code_json/120.json create mode 100644 data_backup/cpp_code_json/121.json create mode 100644 data_backup/cpp_code_json/122.json create mode 100644 data_backup/cpp_code_json/123.json create mode 100644 data_backup/cpp_code_json/124.json create mode 100644 data_backup/cpp_code_json/125.json create mode 100644 data_backup/cpp_code_json/126.json create mode 100644 data_backup/cpp_code_json/127.json create mode 100644 data_backup/cpp_code_json/128.json create mode 100644 data_backup/cpp_code_json/129.json create mode 100644 data_backup/cpp_code_json/13.json create mode 100644 data_backup/cpp_code_json/130.json create mode 100644 data_backup/cpp_code_json/131.json create mode 100644 data_backup/cpp_code_json/132.json create mode 100644 data_backup/cpp_code_json/133.json create mode 100644 data_backup/cpp_code_json/134.json create mode 100644 data_backup/cpp_code_json/135.json create mode 100644 data_backup/cpp_code_json/136.json create mode 100644 data_backup/cpp_code_json/137.json create mode 100644 data_backup/cpp_code_json/138.json create mode 100644 data_backup/cpp_code_json/139.json create mode 100644 data_backup/cpp_code_json/14.json create mode 100644 data_backup/cpp_code_json/140.json create mode 100644 data_backup/cpp_code_json/141.json create mode 100644 data_backup/cpp_code_json/142.json create mode 100644 data_backup/cpp_code_json/143.json create mode 100644 data_backup/cpp_code_json/144.json create mode 100644 data_backup/cpp_code_json/15.json create mode 100644 data_backup/cpp_code_json/16.json create mode 100644 data_backup/cpp_code_json/17.json create mode 100644 data_backup/cpp_code_json/18.json create mode 100644 data_backup/cpp_code_json/19.json create mode 100644 data_backup/cpp_code_json/2.json create mode 100644 data_backup/cpp_code_json/20.json create mode 100644 data_backup/cpp_code_json/21.json create mode 100644 data_backup/cpp_code_json/22.json create mode 100644 data_backup/cpp_code_json/23.json create mode 100644 data_backup/cpp_code_json/24.json create mode 100644 data_backup/cpp_code_json/25.json create mode 100644 data_backup/cpp_code_json/26.json create mode 100644 data_backup/cpp_code_json/27.json create mode 100644 data_backup/cpp_code_json/28.json create mode 100644 data_backup/cpp_code_json/29.json create mode 100644 data_backup/cpp_code_json/3.json create mode 100644 data_backup/cpp_code_json/30.json create mode 100644 data_backup/cpp_code_json/31.json create mode 100644 data_backup/cpp_code_json/32.json create mode 100644 data_backup/cpp_code_json/33.json create mode 100644 data_backup/cpp_code_json/34.json create mode 100644 data_backup/cpp_code_json/35.json create mode 100644 data_backup/cpp_code_json/36.json create mode 100644 data_backup/cpp_code_json/37.json create mode 100644 data_backup/cpp_code_json/38.json create mode 100644 data_backup/cpp_code_json/39.json create mode 100644 data_backup/cpp_code_json/4.json create mode 100644 data_backup/cpp_code_json/40.json create mode 100644 data_backup/cpp_code_json/41.json create mode 100644 data_backup/cpp_code_json/42.json create mode 100644 data_backup/cpp_code_json/43.json create mode 100644 data_backup/cpp_code_json/44.json create mode 100644 data_backup/cpp_code_json/45.json create mode 100644 data_backup/cpp_code_json/46.json create mode 100644 data_backup/cpp_code_json/47.json create mode 100644 data_backup/cpp_code_json/48.json create mode 100644 data_backup/cpp_code_json/49.json create mode 100644 data_backup/cpp_code_json/5.json create mode 100644 data_backup/cpp_code_json/50.json create mode 100644 data_backup/cpp_code_json/51.json create mode 100644 data_backup/cpp_code_json/52.json create mode 100644 data_backup/cpp_code_json/53.json create mode 100644 data_backup/cpp_code_json/54.json create mode 100644 data_backup/cpp_code_json/55.json create mode 100644 data_backup/cpp_code_json/56.json create mode 100644 data_backup/cpp_code_json/57.json create mode 100644 data_backup/cpp_code_json/58.json create mode 100644 data_backup/cpp_code_json/59.json create mode 100644 data_backup/cpp_code_json/6.json create mode 100644 data_backup/cpp_code_json/60.json create mode 100644 data_backup/cpp_code_json/61.json create mode 100644 data_backup/cpp_code_json/62.json create mode 100644 data_backup/cpp_code_json/63.json create mode 100644 data_backup/cpp_code_json/64.json create mode 100644 data_backup/cpp_code_json/65.json create mode 100644 data_backup/cpp_code_json/66.json create mode 100644 data_backup/cpp_code_json/67.json create mode 100644 data_backup/cpp_code_json/68.json create mode 100644 data_backup/cpp_code_json/69.json create mode 100644 data_backup/cpp_code_json/7.json create mode 100644 data_backup/cpp_code_json/70.json create mode 100644 data_backup/cpp_code_json/71.json create mode 100644 data_backup/cpp_code_json/72.json create mode 100644 data_backup/cpp_code_json/73.json create mode 100644 data_backup/cpp_code_json/74.json create mode 100644 data_backup/cpp_code_json/75.json create mode 100644 data_backup/cpp_code_json/76.json create mode 100644 data_backup/cpp_code_json/77.json create mode 100644 data_backup/cpp_code_json/78.json create mode 100644 data_backup/cpp_code_json/79.json create mode 100644 data_backup/cpp_code_json/8.json create mode 100644 data_backup/cpp_code_json/80.json create mode 100644 data_backup/cpp_code_json/81.json create mode 100644 data_backup/cpp_code_json/82.json create mode 100644 data_backup/cpp_code_json/83.json create mode 100644 data_backup/cpp_code_json/84.json create mode 100644 data_backup/cpp_code_json/85.json create mode 100644 data_backup/cpp_code_json/86.json create mode 100644 data_backup/cpp_code_json/87.json create mode 100644 data_backup/cpp_code_json/88.json create mode 100644 data_backup/cpp_code_json/89.json create mode 100644 data_backup/cpp_code_json/9.json create mode 100644 data_backup/cpp_code_json/90.json create mode 100644 data_backup/cpp_code_json/91.json create mode 100644 data_backup/cpp_code_json/92.json create mode 100644 data_backup/cpp_code_json/93.json create mode 100644 data_backup/cpp_code_json/94.json create mode 100644 data_backup/cpp_code_json/95.json create mode 100644 data_backup/cpp_code_json/96.json create mode 100644 data_backup/cpp_code_json/97.json create mode 100644 data_backup/cpp_code_json/98.json create mode 100644 data_backup/cpp_code_json/99.json create mode 100644 data_backup/java_code_json/0.json create mode 100644 data_backup/java_code_json/1.json create mode 100644 data_backup/java_code_json/10.json create mode 100644 data_backup/java_code_json/11.json create mode 100644 data_backup/java_code_json/12.json create mode 100644 data_backup/java_code_json/13.json create mode 100644 data_backup/java_code_json/14.json create mode 100644 data_backup/java_code_json/15.json create mode 100644 data_backup/java_code_json/16.json create mode 100644 data_backup/java_code_json/17.json create mode 100644 data_backup/java_code_json/18.json create mode 100644 data_backup/java_code_json/19.json create mode 100644 data_backup/java_code_json/2.json create mode 100644 data_backup/java_code_json/20.json create mode 100644 data_backup/java_code_json/21.json create mode 100644 data_backup/java_code_json/22.json create mode 100644 data_backup/java_code_json/23.json create mode 100644 data_backup/java_code_json/24.json create mode 100644 data_backup/java_code_json/25.json create mode 100644 data_backup/java_code_json/26.json create mode 100644 data_backup/java_code_json/27.json create mode 100644 data_backup/java_code_json/28.json create mode 100644 data_backup/java_code_json/29.json create mode 100644 data_backup/java_code_json/3.json create mode 100644 data_backup/java_code_json/30.json create mode 100644 data_backup/java_code_json/31.json create mode 100644 data_backup/java_code_json/32.json create mode 100644 data_backup/java_code_json/33.json create mode 100644 data_backup/java_code_json/34.json create mode 100644 data_backup/java_code_json/35.json create mode 100644 data_backup/java_code_json/36.json create mode 100644 data_backup/java_code_json/37.json create mode 100644 data_backup/java_code_json/38.json create mode 100644 data_backup/java_code_json/39.json create mode 100644 data_backup/java_code_json/4.json create mode 100644 data_backup/java_code_json/40.json create mode 100644 data_backup/java_code_json/41.json create mode 100644 data_backup/java_code_json/42.json create mode 100644 data_backup/java_code_json/43.json create mode 100644 data_backup/java_code_json/44.json create mode 100644 data_backup/java_code_json/45.json create mode 100644 data_backup/java_code_json/46.json create mode 100644 data_backup/java_code_json/47.json create mode 100644 data_backup/java_code_json/48.json create mode 100644 data_backup/java_code_json/49.json create mode 100644 data_backup/java_code_json/5.json create mode 100644 data_backup/java_code_json/50.json create mode 100644 data_backup/java_code_json/6.json create mode 100644 data_backup/java_code_json/7.json create mode 100644 data_backup/java_code_json/8.json create mode 100644 data_backup/java_code_json/9.json create mode 100644 data_backup/leetcode/0.json create mode 100644 data_backup/leetcode/1.json create mode 100644 data_backup/leetcode/10.json create mode 100644 data_backup/leetcode/11.json create mode 100644 data_backup/leetcode/12.json create mode 100644 data_backup/leetcode/13.json create mode 100644 data_backup/leetcode/14.json create mode 100644 data_backup/leetcode/15.json create mode 100644 data_backup/leetcode/16.json create mode 100644 data_backup/leetcode/17.json create mode 100644 data_backup/leetcode/18.json create mode 100644 data_backup/leetcode/19.json create mode 100644 data_backup/leetcode/2.json create mode 100644 data_backup/leetcode/20.json create mode 100644 data_backup/leetcode/21.json create mode 100644 data_backup/leetcode/22.json create mode 100644 data_backup/leetcode/23.json create mode 100644 data_backup/leetcode/24.json create mode 100644 data_backup/leetcode/25.json create mode 100644 data_backup/leetcode/26.json create mode 100644 data_backup/leetcode/27.json create mode 100644 data_backup/leetcode/28.json create mode 100644 data_backup/leetcode/29.json create mode 100644 data_backup/leetcode/3.json create mode 100644 data_backup/leetcode/30.json create mode 100644 data_backup/leetcode/31.json create mode 100644 data_backup/leetcode/32.json create mode 100644 data_backup/leetcode/33.json create mode 100644 data_backup/leetcode/34.json create mode 100644 data_backup/leetcode/35.json create mode 100644 data_backup/leetcode/36.json create mode 100644 data_backup/leetcode/37.json create mode 100644 data_backup/leetcode/38.json create mode 100644 data_backup/leetcode/39.json create mode 100644 data_backup/leetcode/4.json create mode 100644 data_backup/leetcode/40.json create mode 100644 data_backup/leetcode/41.json create mode 100644 data_backup/leetcode/42.json create mode 100644 data_backup/leetcode/43.json create mode 100644 data_backup/leetcode/44.json create mode 100644 data_backup/leetcode/45.json create mode 100644 data_backup/leetcode/46.json create mode 100644 data_backup/leetcode/47.json create mode 100644 data_backup/leetcode/48.json create mode 100644 data_backup/leetcode/49.json create mode 100644 data_backup/leetcode/5.json create mode 100644 data_backup/leetcode/50.json create mode 100644 data_backup/leetcode/51.json create mode 100644 data_backup/leetcode/52.json create mode 100644 data_backup/leetcode/53.json create mode 100644 data_backup/leetcode/54.json create mode 100644 data_backup/leetcode/55.json create mode 100644 data_backup/leetcode/56.json create mode 100644 data_backup/leetcode/57.json create mode 100644 data_backup/leetcode/58.json create mode 100644 data_backup/leetcode/59.json create mode 100644 data_backup/leetcode/6.json create mode 100644 data_backup/leetcode/60.json create mode 100644 data_backup/leetcode/61.json create mode 100644 data_backup/leetcode/62.json create mode 100644 data_backup/leetcode/63.json create mode 100644 data_backup/leetcode/64.json create mode 100644 data_backup/leetcode/65.json create mode 100644 data_backup/leetcode/66.json create mode 100644 data_backup/leetcode/67.json create mode 100644 data_backup/leetcode/68.json create mode 100644 data_backup/leetcode/69.json create mode 100644 data_backup/leetcode/7.json create mode 100644 data_backup/leetcode/70.json create mode 100644 data_backup/leetcode/71.json create mode 100644 data_backup/leetcode/72.json create mode 100644 data_backup/leetcode/73.json create mode 100644 data_backup/leetcode/74.json create mode 100644 data_backup/leetcode/75.json create mode 100644 data_backup/leetcode/76.json create mode 100644 data_backup/leetcode/77.json create mode 100644 data_backup/leetcode/78.json create mode 100644 data_backup/leetcode/79.json create mode 100644 data_backup/leetcode/8.json create mode 100644 data_backup/leetcode/80.json create mode 100644 data_backup/leetcode/81.json create mode 100644 data_backup/leetcode/82.json create mode 100644 data_backup/leetcode/83.json create mode 100644 data_backup/leetcode/84.json create mode 100644 data_backup/leetcode/85.json create mode 100644 data_backup/leetcode/86.json create mode 100644 data_backup/leetcode/87.json create mode 100644 data_backup/leetcode/88.json create mode 100644 data_backup/leetcode/89.json create mode 100644 data_backup/leetcode/9.json create mode 100644 data_backup/leetcode/90.json create mode 100644 data_backup/leetcode/91.json create mode 100644 data_backup/leetcode/92.json create mode 100644 data_backup/leetcode/93.json create mode 100644 data_backup/leetcode/94.json create mode 100644 data_backup/leetcode/95.json create mode 100644 data_backup/leetcode/96.json create mode 100644 data_backup/leetcode/97.json create mode 100644 data_backup/leetcode/98.json create mode 100644 data_backup/leetcode/99.json create mode 100644 data_backup/python_code_json/0.json create mode 100644 data_backup/python_code_json/1.json create mode 100644 data_backup/python_code_json/10.json create mode 100644 data_backup/python_code_json/11.json create mode 100644 data_backup/python_code_json/12.json create mode 100644 data_backup/python_code_json/13.json create mode 100644 data_backup/python_code_json/14.json create mode 100644 data_backup/python_code_json/15.json create mode 100644 data_backup/python_code_json/16.json create mode 100644 data_backup/python_code_json/17.json create mode 100644 data_backup/python_code_json/18.json create mode 100644 data_backup/python_code_json/19.json create mode 100644 data_backup/python_code_json/2.json create mode 100644 data_backup/python_code_json/20.json create mode 100644 data_backup/python_code_json/21.json create mode 100644 data_backup/python_code_json/22.json create mode 100644 data_backup/python_code_json/23.json create mode 100644 data_backup/python_code_json/24.json create mode 100644 data_backup/python_code_json/25.json create mode 100644 data_backup/python_code_json/26.json create mode 100644 data_backup/python_code_json/27.json create mode 100644 data_backup/python_code_json/28.json create mode 100644 data_backup/python_code_json/29.json create mode 100644 data_backup/python_code_json/3.json create mode 100644 data_backup/python_code_json/30.json create mode 100644 data_backup/python_code_json/31.json create mode 100644 data_backup/python_code_json/32.json create mode 100644 data_backup/python_code_json/33.json create mode 100644 data_backup/python_code_json/34.json create mode 100644 data_backup/python_code_json/35.json create mode 100644 data_backup/python_code_json/36.json create mode 100644 data_backup/python_code_json/37.json create mode 100644 data_backup/python_code_json/38.json create mode 100644 data_backup/python_code_json/39.json create mode 100644 data_backup/python_code_json/4.json create mode 100644 data_backup/python_code_json/40.json create mode 100644 data_backup/python_code_json/41.json create mode 100644 data_backup/python_code_json/42.json create mode 100644 data_backup/python_code_json/43.json create mode 100644 data_backup/python_code_json/44.json create mode 100644 data_backup/python_code_json/45.json create mode 100644 data_backup/python_code_json/46.json create mode 100644 data_backup/python_code_json/47.json create mode 100644 data_backup/python_code_json/48.json create mode 100644 data_backup/python_code_json/49.json create mode 100644 data_backup/python_code_json/5.json create mode 100644 data_backup/python_code_json/50.json create mode 100644 data_backup/python_code_json/6.json create mode 100644 data_backup/python_code_json/7.json create mode 100644 data_backup/python_code_json/8.json create mode 100644 data_backup/python_code_json/9.json diff --git a/data/cpp/test.md b/data/cpp/test.md new file mode 100644 index 000000000..e69de29bb diff --git a/data_backup/cpp_code_json/0.json b/data_backup/cpp_code_json/0.json new file mode 100644 index 000000000..38f1b8244 --- /dev/null +++ b/data_backup/cpp_code_json/0.json @@ -0,0 +1,18 @@ +{ + "question_id": 702203, + "question_title": "检查一个3位数是否是水仙花数", + "question_content": "检查一个3位数是否是水仙花数。\n输入:一个数字,比如 371,输出:x是水仙花数,\n如果不是,则输出:x不是水仙花数。\n注:x为输入的数字", + "difficulty": "简单", + "answer_id": 592515, + "answer_content": "\n\n```\n #include \nusing namespace std;\nint main()\n{\n\tint a, b, c, y, n = 0;\n\tcout << \"请输入三位数字:\" << endl;\n\tcin >> n;\n\n\ta = n % 1000 / 100; //求第一位数 \n\tb = n % 100 / 10; //求第二位数\n\tc = n % 10 / 1; //求第三位数 \n\ty = a*a*a + b*b*b + c*c*c;\n\tif (y == n) cout << n << \"是水仙花数\" << endl;\n\telse cout << n << \"不是水仙花数\" << endl;\n\t\n\n\tsystem(\"pause\");\n\treturn 0;\n}\n```\n\n", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint main()\n{\n\tint a, b, c, y, n = 0;\n\tcout << \"请输入三位数字:\" << endl;\n\tcin >> n;\n\ta = n % 1000 / 100; \n\tb = n % 100 / 10;\t\n\tc = n % 10 / 1;\t \n\ty = a*a*a + b*b*b + c*c*c;\n\tif (y == n) cout << n << \"是水仙花数\" << endl;\n\telse cout << n << \"不是水仙花数\" << endl;\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469841", + "status": 1, + "keywords": "数学,算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/0.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/1.json b/data_backup/cpp_code_json/1.json new file mode 100644 index 000000000..b47237f05 --- /dev/null +++ b/data_backup/cpp_code_json/1.json @@ -0,0 +1,18 @@ +{ + "question_id": 7437073, + "question_title": "编写递归函数和非递归函数", + "question_content": "

编写一个递归函数和一个非递归函数,分别实现求1+2+3+...+n

", + "difficulty": "简单", + "answer_id": 53409711, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n//递归方法\nint sum(int n)\n{\n\tif(n == 1)\n\t\treturn 1;\n\telse\n\t\treturn n + sum(n-1);\n}\n\n//非递归方法\nint sum_2(int n)\n{\n\tint ss = 0;\n\tfor (int i = 1; i <=n;i++)\n\t{\n\t\tss += i; \n\t}\n\treturn ss;\n}\n\nint main()\n{\n\tint n;\n\tprintf("请输入n:");\n\tscanf("%d",&n);\n\t\n\tint s1 = sum(n);\n\tint s2 = sum_2(n);\n\tprintf("递归计算=%d;循环计算=%d\\n",s1,s2);\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint sum(int n)\n{\n\tif(n == 1)\n\t\treturn 1;\n\telse\n\t\treturn n + sum(n-1);\n}\nint sum_2(int n)\n{\n\tint ss = 0;\n\tfor (int i = 1; i <=n;i++)\n\t{\n\t\tss += i; \n\t}\n\treturn ss;\n}\nint main()\n{\n\tint n;\n\tprintf(\"请输入n:\");\n\tscanf(\"%d\",&n);\n\tif(n == 0)\n\t\t{\n\t\t\tprintf(\"请输入正整数n\");\n\t\t\treturn -1;\n\t\t}\n\tint s1 = sum(n);\n\tint s2 = sum_2(n);\n\tprintf(\"递归计算=%d;循环计算=%d\\n\",s1,s2);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470242", + "status": 1, + "keywords": "递归,算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/1.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/10.json b/data_backup/cpp_code_json/10.json new file mode 100644 index 000000000..15c6393c3 --- /dev/null +++ b/data_backup/cpp_code_json/10.json @@ -0,0 +1,18 @@ +{ + "question_id": 1071974, + "question_title": "输入两个小写英语字母后, 输出两个字母的差", + "question_content": "两个小写字母的差用整数输出。\n但是,输入小写以外的文字就结束程序。\n比较两个字母的部分用diff这个名字的函数书写。执行结果\n请输入两个小写:a b\n字母a和字母b的区别是1。\n请输入两个小写:f b\n字母f和字母b的差异是4。\n请输入两个小写:0 a\n退出程序。", + "difficulty": "简单", + "answer_id": 1274118, + "answer_content": "\n```\n#include \nusing namespace std;\nint diff(char ch1, char ch2)\n{\nif (ch1 > ch2) return ch1 - ch2; else return ch2 - ch1;\n}\nint main()\n{\nchar a, b;\nwhile (1)\n{\ncout << \"请输入两个小写:\";\ncin >> a >> b;\nif (a >= 'z' || a <= 'a' || b >= 'z' || b <= 'a') break;\ncout << \"文字\" << a << \"和文字\" << b << \"的差异是\" << diff(a, b) << \"。\\n\";\n}\nreturn 0;\n}\n```\n# 问题解决的话,请点下采纳", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint diff(char ch1, char ch2)\n{\n\tif (ch1 > ch2) return ch1 - ch2; else return ch2 - ch1;\n}\nint main()\n{\n\tchar a, b;\n\twhile (1)\n\t{\n\t\tcout << \"请输入两个小写:\";\n\t\tcin >> a >> b;\n\t\tif (a > 'z' || a < 'a' || b > 'z' || b < 'a') break;\n\t\tcout << \"文字\" << a << \"和文字\" << b << \"的差异是\" << diff(a, b) << \"。\\n\";\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470248", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/10.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/100.json b/data_backup/cpp_code_json/100.json new file mode 100644 index 000000000..983076a84 --- /dev/null +++ b/data_backup/cpp_code_json/100.json @@ -0,0 +1,18 @@ +{ + "question_id": 7446447, + "question_title": "判断是否能组成三角形", + "question_content": "

根据输入的三角形的三边判断是否能组成三角形,若可以则输出它的周长和三角的类型

", + "difficulty": "简单", + "answer_id": 53425759, + "answer_content": "
\n#include<stdlib.h>\n#include<stdio.h>\nint  main ( void )\n{\n\tint num1,num2,num3;\n\tprintf("请输入第一条边:");\n\tscanf("%d",&num1);\n\tprintf("请输入第二条边:");\n\tscanf("%d",&num2);\n\tprintf("请输入第三条边:");\n\tscanf("%d",&num3);\n\tif(num1+num2>num3&&num2+num3>num1&&num1+num3>num2)\n\t{\n\t\tif (num1*num1+num2*num2==num3*num3||num2*num2+num3*num3==num1*num1||num1*num1+num3*num3==num2*num2){\n\t\t\tprintf ( "%d、%d和%d可以组成直角三角形。\\n " ,num1,num2,num3);\n\t\t\tprintf ("三角形周长:%d\\n",num1+num2+num3);\n\t\t}\n\t\t\n\telse if (num1*num1+num2*num2<num3*num3||num2*num2+num3*num3<num1*num1||num1*num1+num3*num3<num2*num2)\n\t\t\t{\n\t\t\t\tprintf ("%d、%d和%d可以组成锐角三角形。\\n" ,num1,num2,num3);\n\t\t\t\tprintf ("三角形周长:%d\\n",num1+num2+num3);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tprintf ("%d、%d和%d可以组成钝角三角形\\n" ,num1,num2,num3);\n\t\t\t\tprintf ("三角形周长:%d\\n",num1+num2+num3);\n\t\t\t}\n\t}\n\telse\n\t\tprintf("%d, %d和%d不能组成三角形。\\n",num1,num2,num3);\n\tsystem("PAUSE");\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include\n#include\nint main(void)\n{\n\tint num1,num2,num3;\n\tprintf(\"请输入第一条边:\");\n\tscanf(\"%d\",&num1);\n\tprintf(\"请输入第二条边:\");\n\tscanf(\"%d\",&num2);\n\tprintf(\"请输入第三条边:\");\n\tscanf(\"%d\",&num3);\n\tif(num1+num2>num3&&num2+num3>num1&&num1+num3>num2)\n\t{\n\t\tif (num1*num1+num2*num2==num3*num3||num2*num2+num3*num3==num1*num1||num1*num1+num3*num3==num2*num2){\n\t\t\tprintf ( \"%d、%d和%d可以组成直角三角形。\\n \" ,num1,num2,num3);\n\t\t\tprintf (\"三角形周长:%d\\n\",num1+num2+num3);\n\t\t}\n\telse if (num1*num1+num2*num2

分别统计一个字符串中出现小写字母、大写字母、数字和空格的个数。\n输入格式:\n在一行中输入长度不超过40的字符串。\n输出格式:\n第一行中输出“小写字母=x“ 第二行中输出“大写字母=y“ 第三行中输出“数字=z” 第四行中输出“空格=m” 所有结果均原样输出,没有列宽控制。

\n

输入样例:

\nsd2h b57 sA\n

输出样例:

\n
\n小写字母=5\n大写字母=1\n数字=3\n空格=2
", + "difficulty": "简单", + "answer_id": 53428190, + "answer_content": "

对每个字符做判断就可以了。

\n\n
\n#include<stdio.h>\nint main()\n{\nint a=0,b=0,c=0,d=0,e=0;\nchar *p,str[80];\np=str;\ngets(str);\nwhile(*p)\nif(*p>='A' && *p <='Z')\n{a++;p++;}\nelse if(*p>='a' && *p <='z')\n{b++;p++;}\nelse if(*p==' ')\n{c++;p++;}\nelse if(*p>='0' && *p <='9')\n{d++;p++;}\nelse\n{e++;p++;}\nprintf("%d %d %d %d %d\\n",a,b,c,d,e);\nreturn 0;\n}
\n\n

如有帮助往采纳。点击我回答右上角【采纳】按钮。

\n", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint a=0,b=0,c=0,d=0,e=0;\n\tchar *p,str[80];\n\tp=str;\n\tgets(str);\n\twhile(*p)\n\tif(*p>='A' && *p <='Z')\n\t\t{a++;p++;}\n\telse if(*p>='a' && *p <='z')\n\t\t{b++;p++;}\n\telse if(*p==' ')\n\t\t{c++;p++;}\n\telse if(*p>='0' && *p <='9')\n\t\t{d++;p++;}\n\telse\n\t\t{e++;p++;}\n\tprintf(\"%d %d %d %d %d\\n\",a,b,c,d,e);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470174", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/101.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/102.json b/data_backup/cpp_code_json/102.json new file mode 100644 index 000000000..d7faa7d68 --- /dev/null +++ b/data_backup/cpp_code_json/102.json @@ -0,0 +1,17 @@ +{ + "question_id": 7433939, + "question_title": "员工工资统计", + "question_content": "

一公司有10名员工,每位员工的信息包括;员工编号,姓名,工资;要求编写函数实现:\n1.输入10名员工的信息。\n2.输出平均工资及所有工资高于平均工资的职工的姓名。\n呜呜呜是老师布置的作业,要用c语言编写,可是俺啥也不会,sos,希望能有人帮忙_(:3 ⌒゙)_

", + "difficulty": "简单", + "answer_id": 53404281, + "answer_content": "
\n#include <stdio.h>\n#include <stdlib.h>\nstruct Worker{\n     int Number;\n     char Name[50] ;\n     int Age;\n     float Salary;\n}s[10], *p=s;\nint main(int argc, char *argv[]) {\n    float sum=0.0;\n    for(int i=0;i<3;i++){\n        struct Worker work;\n        printf("请输入第%d个员工信息:\\n",i+1);\n        printf("工号:");\n        scanf("%d",&work.Number); \n        printf("姓名:");\n        scanf("%s",&work.Name); \n        printf("年龄:");\n        scanf("%d",&work.Age); \n        printf("工资:");\n        scanf("%f",&work.Salary); \n        sum+=work.Salary;\n        printf("输入完成!\\n");\n        p[i]=work;\n    }\n     printf("平均工资为:%0.3f\\n",sum/10);\n     printf("高于平均工资的姓名如下:\\n");\n     for(int j=0;j<10;j++){\n\t\tif (p[j].Salary>sum/10) {\n\t\t\tprintf("%s\\n",p[j].Name); \n\t\t}\n\t }\n    return 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nstruct Worker{\n\t int Number;\n\t char Name[50] ;\n\t int Age;\n\t float Salary;\n}s[10], *p=s;\nint main(int argc, char *argv[]) {\n\tfloat sum=0.0;\n\tfor(int i=0;i<3;i++){\n\t\tstruct Worker work;\n\t\tprintf(\"请输入第%d个员工信息:\\n\",i+1);\n\t\tprintf(\"工号:\");\n\t\tscanf(\"%d\",&work.Number); \n\t\tprintf(\"姓名:\");\n\t\tscanf(\"%s\",&work.Name); \n\t\tprintf(\"年龄:\");\n\t\tscanf(\"%d\",&work.Age); \n\t\tprintf(\"工资:\");\n\t\tscanf(\"%f\",&work.Salary); \n\t\tsum+=work.Salary;\n\t\tprintf(\"输入完成!\\n\");\n\t\tp[i]=work;\n\t}\n\t printf(\"平均工资为:%0.3f\\n\",sum/10);\n\t printf(\"高于平均工资的姓名如下:\\n\");\n\t for(int j=0;j<10;j++){\n\t\tif (p[j].Salary>sum/10) {\n\t\t\tprintf(\"%s\\n\",p[j].Name); \n\t\t}\n\t }\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469858", + "status": 0, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/102.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/103.json b/data_backup/cpp_code_json/103.json new file mode 100644 index 000000000..7307dc182 --- /dev/null +++ b/data_backup/cpp_code_json/103.json @@ -0,0 +1,18 @@ +{ + "question_id": 7462901, + "question_title": "存了多少零钱", + "question_content": "

小林和小树兄弟俩相约存零钱。眼看到年底了,兄弟俩决定算算一共存了多少钱,请帮他们算出来。

输入:

两行,第一行三个整数分别对应元、角、分,表示小林存的零钱数;

第二行三个整数分别对应元、角、分,表示小树存的零钱数。

输出:

两人存的钱数(单位:元,保留2位小数)

样例输入:

30 5 5

45 7 4

样例输出:

76.29

", + "difficulty": "简单", + "answer_id": 53448638, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n\nint main()\n{\n\tint y1,j1,f1,y2,j2,f2;\n\tint y,j,f;\n\tint shiftj = 0;\n\tint shifty = 0;\n\tfloat ss ;\n\tscanf("%d %d %d",&y1,&j1,&f1);\n\tscanf("%d %d %d",&y2,&j2,&f2);\n\n\t\n\tf = f1 + f2;\n\tif(f>=10)\n\t{\n\t\tf = f-10;\n\t\tshiftj = 1;\n\t}\n\tj = j1 + j2 + shiftj;\n\tif(j >= 10)\n\t{\n\t\tj = j - 10;\n\t\tshifty = 1;\n\t}\n\ty = y1 + y2 + shifty;\n\t\n\tss = y + j/10.0 + f/100.0;\n\tprintf("%.2f\\n",ss);\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \nint main()\n{\n\tint y1,j1,f1,y2,j2,f2;\n\tint y,j,f;\n\tint shiftj = 0;\n\tint shifty = 0;\n\tfloat ss ;\n\tscanf(\"%d %d %d\",&y1,&j1,&f1);\n\tscanf(\"%d %d %d\",&y2,&j2,&f2);\n\tf = f1 + f2;\n\tif(f>=10)\n\t{\n\t\tf = f-10;\n\t\tshiftj = 1;\n\t}\n\tj = j1 + j2 + shiftj;\n\tif(j >= 10)\n\t{\n\t\tj = j - 10;\n\t\tshifty = 1;\n\t}\n\ty = y1 + y2 + shifty;\n\tss = y + j/10.0 + f/100.0;\n\tprintf(\"%.2f\\n\",ss);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470175", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/103.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/104.json b/data_backup/cpp_code_json/104.json new file mode 100644 index 000000000..563106efb --- /dev/null +++ b/data_backup/cpp_code_json/104.json @@ -0,0 +1,18 @@ +{ + "question_id": 7450404, + "question_title": "将字符串2小写字母复制到字符串1", + "question_content": "

编写程序,输入字符串s2,将其中所有小写字母复制到字符串数组strl中。例如
\naal1bb22cc33de4AA55BB”,生成的strl为"aabbccde"。

", + "difficulty": "简单", + "answer_id": 53431030, + "answer_content": "
\n#include<stdio.h>\n\n\nint main()\n{\n    int sum=0,t=0,i;\n    char s[50],s1[50];\n    scanf("%s",s);\n    for(i=0;s[i]!='\\0';i++)\n    {\n        if(s[i]>='a'&&s[i]<='z'){\n            s1[t++]=s[i];\n        }\n    }\n    s1[t]='\\0';\n    printf("%s",s1);\n}\n
\n\n

\"\" 

\n", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint sum=0,t=0,i;\n\tchar s[50],s1[50];\n\tscanf(\"%s\",s);\n\tfor(i=0;s[i]!='\\0';i++)\n\t{\n\t\tif(s[i]>='a'&&s[i]<='z'){\n\t\t\ts1[t++]=s[i];\n\t\t}\n\t}\n\ts1[t]='\\0';\n\tprintf(\"%s\",s1);\n}", + "topic_link": "https://bbs.csdn.net/topics/600469859", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/104.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/105.json b/data_backup/cpp_code_json/105.json new file mode 100644 index 000000000..1f2f633ba --- /dev/null +++ b/data_backup/cpp_code_json/105.json @@ -0,0 +1,18 @@ +{ + "question_id": 1058389, + "question_title": "秒数转换", + "question_content": "输入一个秒数,转换成HH:MM:SS的格式输出。\n输入样例 \n365\n输出样例 \n00:06:05", + "difficulty": "简单", + "answer_id": 1255698, + "answer_content": "\n```\n#include\nint n;\nvoid print(int x){\n\tif(x==0)printf(\"00\");\n\telse if(x<10)printf(\"0%d\",x);\n\telse printf(\"%d\",x);\n\treturn;\n}\nint main(){\n\tscanf(\"%d\",&n);\n\tint s,f,m;\n\ts=n/3600;\n\tf=n/60%60;\n\tm=n%60;\n\tprint(s);\n\tprintf(\":\");\n\tprint(f);\n\tprintf(\":\");\n\tprint(m);\n\treturn 0;\n}\n```\n如果还没有学过函数的话,可以这么做\n\n```\n#include\nint n;\nint main(){\n\tscanf(\"%d\",&n);\n\tprintf(\"%d%d:%d%d:%d%d\",n/3600/10,n/3600%10,n/60%60/10,n/60%10,n%60/10,n%10);\n\treturn 0;\n}\n```", + "tag_name": "c++", + "cpp": "#include\nint n;\nvoid print(int x){\n\tif(x==0)printf(\"00\");\n\telse if(x<10)printf(\"0%d\",x);\n\telse printf(\"%d\",x);\n\treturn;\n}\nint main(){\n\tscanf(\"%d\",&n);\n\tint s,f,m;\n\ts=n/3600;\n\tf=n/60%60;\n\tm=n%60;\n\tprint(s);\n\tprintf(\":\");\n\tprint(f);\n\tprintf(\":\");\n\tprint(m);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470176", + "status": 1, + "keywords": "时间转换", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/105.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/106.json b/data_backup/cpp_code_json/106.json new file mode 100644 index 000000000..0b55e806b --- /dev/null +++ b/data_backup/cpp_code_json/106.json @@ -0,0 +1,18 @@ +{ + "question_id": 1056814, + "question_title": "寻找孪生素数", + "question_content": "数学家希尔伯特在1900年国际数学家大会的报告上提出一个“孪生素数猜想”,即: 存在无穷多个素数p,使得p + 2是素数。p和p+2这一对差为2的素数,被称为“孪生素数”。\n看起来,这个猜想是成立的,我们总能找到很多对孪生素数,例如:3和5,5和7,11和13…… 这一猜想至今还未被证明。\n现在,对于给定的整数n, 请寻找大于n的最小的一对孪生素数p和q(q=p+2)。", + "difficulty": "困难", + "answer_id": 1253864, + "answer_content": "你的sushu判断不对,比如说121,1,这些都不是素数,但是你都返回真了。\n```\n#include \n#include \n\nusing namespace std;\nint sushu(int x)\n{\nif (x <= 1) return 0;\nint i,j=1;\nfor(i=2;i<=sqrt(x);i++)\n{\nif(x%i==0){j=0;break;}\n}\nreturn j;\n}\nint main()\n{\nint x;\ncin>>x;\nint i=x+1;\nfor(;;i++)\n{\nif (sushu(i)&&sushu(i+2))\nbreak;\n}\ncout<\n#include \nusing namespace std;\nint sushu(int x)\n{\n\tif (x <= 1) return 0;\n\tint i,j=1;\n\tfor(i=2;i<=sqrt(x);i++)\n\t{\n\t\tif(x%i==0){j=0;break;}\n\t}\n\treturn j;\n}\nint main()\n{\n\tint x;\n\tcin>>x;\n\tint i=x+1;\n\tfor(;;i++)\n\t{\n\t\tif (sushu(i)&&sushu(i+2))\n\t\t\tbreak;\n\t}\n\tcout<\n#include \nint main()\n{\n char a[21];\n scanf(\"%s\",a);\n int t,j=0,i=0;\n int n = strlen(a);\n for(j=1;j < n; j++){\n for(i=0;i a[j]) break;\n }\n int t=a[j];\n int t1;\n for(;i<=j;i++){\n\t\t\tt1=a[i];\n\t\t\ta[i]=t;\n\t\t\tt=t1;\n }\n }\n printf(\"%s\",a);\n return 0;\n}\n\n```\nhttps://ideone.com/QL7g22 在线调试通过\n\n\n下面是选择排序\n```\n#include \n#include \nint main()\n{\n\tchar a[21];\n\tscanf(\"%s\",a);\n\tint t,j=0,i=0;\n\tint n = strlen(a);\n\tfor(j=0;j < n - 1; j++){\n\t\tint min = j;\n\t\tfor(i=j+1;i < n; i++) {\n\t\t\tif (a[i] < a[min]) min=i;\n\t\t}\n\t\tif (min != j) {\n\t\t\tt=a[min];\n\t\t\ta[min]=a[j];\n\t\t\ta[j]=t;\n\t\t}\n\t}\n\tprintf(\"%s\",a);\n\treturn 0;\n}\n```", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tchar a[21];\n\tscanf(\"%s\",a);\n\tint t,j=0,i=0;\n\tint n = strlen(a);\n\tfor(j=1;j < n; j++){\n\t\tfor(i=0;i a[j]) break;\n\t\t}\n\t\tint t=a[j];\n\t\tint t1;\n\t\tfor(;i<=j;i++){\n\t\t\tt1=a[i];\n\t\t\ta[i]=t;\n\t\t\tt=t1;\n\t\t}\n\t}\n\tprintf(\"%s\",a);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470272", + "status": 1, + "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/107.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/108.json b/data_backup/cpp_code_json/108.json new file mode 100644 index 000000000..c0bb0b33d --- /dev/null +++ b/data_backup/cpp_code_json/108.json @@ -0,0 +1,18 @@ +{ + "question_id": 720288, + "question_title": "找x", + "question_content": "题目描述\n输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。\n输入\n测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。\n输出\n对于每组输入,请输出结果。\n样例输入\n4\n1 2 3 4\n3\n样例输出\n2\n", + "difficulty": "困难", + "answer_id": 714710, + "answer_content": "折半查找是不行的,折半查找有一个前提那就是:数组的数必须有序,不然效率低的可怜。下面我写的,比较简单,什么也没做处理,你要的功能基本实现,根据这个改下吧\n\n#include \n\nusing namespace std;\n\nint main() {\n\tint n = 0;\n\tcin >> n;\n\n\tint* ptr = new(nothrow) int[n];\n\tfor (auto i = 0; i < n; i++) {\n\t\tcin >> ptr[i];\n\t}\n\n\tint x = 0;\n\tcin >> x;\n\n\tauto j = 0;\n\tauto status = 0;\n\tfor (; j < n; ++j) {\n\t\tif (ptr[j] == x) {\n\t\t\tstatus = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (status == 0) {\n\t\tj = -1;\n\t}\n\tcout << j << endl;\n\t\n\tdelete[] ptr;\n\n\tcin.get();\n\tcin.get();\n\n\treturn 0;\n}\n```\n\n```", + "tag_name": "c语言", + "cpp": "#include \nusing namespace std;\nint main() {\n\tint n = 0;\n\tcin >> n;\n\tint* ptr = new(nothrow) int[n];\n\tfor (auto i = 0; i < n; i++) {\n\t\tcin >> ptr[i];\n\t}\n\tint x = 0;\n\tcin >> x;\n\tauto j = 0;\n\tauto status = 0;\n\tfor (; j < n; ++j) {\n\t\tif (ptr[j] == x) {\n\t\t\tstatus = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (status == 0) {\n\t\tj = -1;\n\t}\n\tcout << j << endl;\n\tdelete[] ptr;\n\tcin.get();\n\tcin.get();\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470177", + "status": 1, + "keywords": "算法初阶,基础知识,分治策略,最大子数组问题", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/108.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/109.json b/data_backup/cpp_code_json/109.json new file mode 100644 index 000000000..7968c8485 --- /dev/null +++ b/data_backup/cpp_code_json/109.json @@ -0,0 +1,18 @@ +{ + "question_id": 7411209, + "question_title": "阶乘和数", + "question_content": "一个正整数如果等于组成它的各位数字的阶乘之和,该整数称为阶乘和数。\n例如,145=1!+4!+5!,则145是一个三位阶乘和数。\n请输出所有阶乘数(不会超过十万)", + "difficulty": "困难", + "answer_id": 53361950, + "answer_content": "

循环太多,系统卡死

\n\n

#include <stdio.h>

\n\n

int b[10] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};

\n\n

int main(){
\n    int x, sum = 0, a;
\n    for(int j = 1; j <= 100000; j++){
\n        sum = 0; 
\n        a = j;
\n        while(j != 0){
\n            x = j % 10;
\n            j /= 10;
\n            sum += b[x];
\n        }
\n        j = a;
\n        if(sum == a){
\n            printf("%d ", j);
\n        }
\n    }
\n    return 0;
\n} 

", + "tag_name": "c语言", + "cpp": "#include \nint b[10] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};\nint main(){\n    int x, sum = 0, a;\n    for(int j = 1; j <= 100000; j++){\n        sum = 0; \n        a = j;\n        while(j != 0){\n            x = j % 10;\n            j /= 10;\n            sum += b[x];\n        }\n        j = a;\n        if(sum == a){\n            printf(\"%d \", j);\n        }\n    }\n    return 0;\n} ", + "topic_link": "https://bbs.csdn.net/topics/600469860", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/109.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/11.json b/data_backup/cpp_code_json/11.json new file mode 100644 index 000000000..8426aa1f6 --- /dev/null +++ b/data_backup/cpp_code_json/11.json @@ -0,0 +1,18 @@ +{ + "question_id": 6722211, + "question_title": "怎么求尾数与常数之和?", + "question_content": "

数列的前3项都为1,从第4项开始,每项都是其前3项的和:1, 1, 1, 3, 5, 9, 17, … 请你编程求出数列第N项的4位尾数与90000之和。输入一个正整数N,输出所求的和。

", + "difficulty": "简单", + "answer_id": 47620887, + "answer_content": "

#include<iostream>

\n\n

#include<cstring>

\n\n

#include<cstdio>

\n\n

#include<cstdlib>

\n\n

#include<cmath>

\n\n

#include<iomanip>

\n\n

#include<algorithm>

\n\n

#include<set>

\n\n

using namespace std;

\n\n

#define NUM 10000//符号常量

\n\n

long long dp[1000000];

\n\n

int main(){

\n\n

    //freopen("E:\\\\VSCode_C++\\\\test.txt","r",stdin);

\n\n

    int n;

\n\n

    cin>>n;

\n\n

    dp[1]=1;

\n\n

    dp[2]=1;

\n\n

    dp[3]=1;

\n\n

    for(int i=4;i<=n;i++){

\n\n

        dp[i]=dp[i-1]+dp[i-2]+dp[i-3];

\n\n

    }

\n\n

    cout<<dp[n]<<endl;

\n\n

    long long x=dp[n]%10000+9000;

\n\n

    cout<<x;

\n\n

    system("pause");

\n\n

    return 0;

\n\n

}

", + "tag_name": "c语言", + "cpp": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n#define NUM 10000\nlong long dp[1000000];\nint main(){\n    int n;\n    cin>>n;\n    dp[1]=1;\n    dp[2]=1;\n    dp[3]=1;\n    for(int i=4;i<=n;i++){\n        dp[i]=dp[i-1]+dp[i-2]+dp[i-3];\n    }\n    cout<问题描述\n经营一家糖果店是非常困难的,你需要优化各种各样的东西。最近你在销售一种非常时髦的糖果,叫做Whizboppers。这种糖果变质非常迅速,所以:
\n  ·你必须每天早上从供应商买来新的Whizboppers。
\n  ·你必须用当天早上从供应商买来的盒子装着糖果出售。
\n  你可以从你的供应商处买来装有任意整数克糖果的盒子。
\n  每天有至多k位顾客到你的店里来。从第1个人开始,每个人会选择花费整数分的钱来买Whizboppers,钱数在1分到C分之间(包含1分和C分)。你打算以1分钱每克的价格出售;所以如果一个人想要花4分钱,你会给他恰好4克糖果。你可以给他1个4克的盒子,也可能是1个2克的盒子和2个1克的盒子。
\n  你最少需要买几个盒子才能保证,不管每个人想花多少钱买糖,你总是可以给他们对应质量的糖果?\n
  注意:当一个人选择自己想买多少糖果后,你知道之前的人已经买了多少糖,但不能预知之后的人打算买多少糖。
\n  举个例子,如果每天至多有2位顾客到你的店里,每个人至多花2分钱(k=2,C=2),你可以从你的供应商买4个1克的盒子。但是你可以做的更好:只要买2个1克的盒子和1个2克的盒子,就可以满足你的顾客。如下所示:
\n第一个人给第一个人的盒子第二个人给第二个人的盒子2分1 个 2克2分
\n1分2 个 1克
\n1 个 1克1分1 个 1克2分
\n1分1 个 2克
\n1 个 1克
  不论第一个人怎么买,你都可以给他对应质量的盒子,同时保证第二个人也能拿到正确质量的糖果。所以对于k=2,C=2,你用3个盒子就可以满足任意的顾客需求。\n输入格式\n  第一行一个整数T,表示询问数量。\n  接下来T行,每行包含两个整数k和C,分别表示最大人数和每个人花费的最多钱数。\n输出格式\n  对于每一个询问,输出一行包含"Case #x: y",x是询问编号(从1开始标号),y是你每天最少需要的盒子数量。

", + "difficulty": "困难", + "answer_id": 53386266, + "answer_content": "

帮你梳理一下思路,这个问题有两个关键点:

\n\n

1、需要的盒子的容量必须大于等于顾客的最大购买量。

\n\n

2、不论哪种情况,永远从2个1克的盒子开始计算。

\n\n

例如,样例2 2,即每天至多有2位顾客到你的店里,每个人至多花2分钱,此时:

\n\n

1)最大购买数量为:2*2=4g

\n\n

2)先给定两个1克的盒子:1g*2,容量:2g

\n\n

如果每人购买2g,则总共需要可装4g的盒子,此时的问题是:如何确定下一个盒子?

\n\n

当然,题目已经告诉我们了还需要1个2g的盒子,那么这个1个如何确定的呢?

\n\n

确定方法:(4-2)/2=1。

\n\n

至此,容量为4g,满足最大购买数量,需要3个盒子,规格为:1g*2,2g*1。

\n\n

当然也有除不尽的情况,方法是向上取整。

\n\n

例如,样例:1 5,即每天至多有1位顾客到店,至多花费5分钱,此时:

\n\n

1)最大购买数量为:1*5=5g

\n\n

2)先给定两个1克的盒子:1g*2,容量:2g

\n\n

如果这个顾客购买3g,此时的问题是:如何确定下一个盒子?

\n\n

确定方法:(3-2)/3=0.333,向上取整为1,所以还需要1个3g的盒子。

\n\n

至此,容量为5g,满足最大购买数量,需要3个盒子,规格为:1g*2,3g*1。

\n\n

再比如,样例2 50,即每天至多有2位顾客到店,至多花费50分钱,此时:

\n\n

1)最大购买数量为:2*50=100g

\n\n

2)先给定两个1克的盒子:1g*2,容量:2g

\n\n

如果每人购买2g,则还需要1个2g的盒子(前面已给出),此时容量为4g

\n\n

如果每人购买3g,则总共需要可装6g的盒子,此时的问题依然是:如何确定下一个盒子?

\n\n

确定方法:(6-4)/3=0.67,向上取整为1,所以还需要1个3g的盒子,此时容量为7g

\n\n

如果每人购买4g,则需要可装8g的盒子,此时的问题依然是:如何确定下一个盒子?

\n\n

确定方法:(8-7)/4=0.25,向上取整为1,所以还需要1个4g的盒子,此时容量为11g

\n\n

如果每人购买6g,则需要可装12g的盒子,此时的问题依然是:如何确定下一个盒子?

\n\n

确定方法:(12-11)/6=1/6,向上取整为1,所以还需要1个6g的盒子,此时容量为17g

\n\n

为什么是:如果每人购买6g?因为每次“如果”,都要使需要的容量超过了前一次的容量。

\n\n

......

\n\n

以此类推,直到容量大于等于100g,最终发现需要的盒子数量是11个,规格为:1g*2,2g*1,3g*1,4g*1,6g*1,......

\n\n

这就是这个问题的基本思路。

\n\n

代码可以参考:

\n\n
\n#include<iostream>\n#include<cmath>\nusing namespace std;\n\nint main()\n{\n\tint n, k, count = 1;\n\tlong long c;\n\tcin >> n;\n\twhile (n--)\n\t{\n\t\tcin >> k >> c;\n\t\tint num = k; \n\t\tlong long sum = k;\n\t\tfor (long long i = 2; i <= c; i = sum / k + 1)\n\t\t{\n\t\t\tint t = num;\n\t\t\tnum += ceil((k * i - sum) * 1.0 / i);\n\t\t\tsum += i * (num - t);\n\t\t}\n\t\tcout << "Case #" << count++ <<": " << num << endl;\n\t}\n\treturn 0;\n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\n#include\nusing namespace std;\nint main()\n{\n\tint n, k, count = 1;\n\tlong long c;\n\tcin >> n;\n\twhile (n--)\n\t{\n\t\tcin >> k >> c;\n\t\tint num = k; \n\t\tlong long sum = k;\n\t\tfor (long long i = 2; i <= c; i = sum / k + 1)\n\t\t{\n\t\t\tint t = num;\n\t\t\tnum += ceil((k * i - sum) * 1.0 / i);\n\t\t\tsum += i * (num - t);\n\t\t}\n\t\tcout << \"Case #\" << count++ <<\": \" << num << endl;\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470178", + "status": 1, + "keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/110.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/111.json b/data_backup/cpp_code_json/111.json new file mode 100644 index 000000000..1cce901c7 --- /dev/null +++ b/data_backup/cpp_code_json/111.json @@ -0,0 +1,18 @@ +{ + "question_id": 237159, + "question_title": "按字典顺序排列问题", + "question_content": "输入若干英文单词,将每个单词的首字母转换成大写字母,其他字母为小写,并按字典顺序排列", + "difficulty": "中等", + "answer_id": 216930, + "answer_content": "\n\n```\n #include \n#include \n#include \n\nint cmp(const void * a, const void * b)\n{\n\treturn strcmp(*(char **)a, *(char **)b);\n}\n\nint main(int argc, char* argv[])\n{\n\tint n = 0;\n\tint i;\n\tprintf(\"how many words?\\n\");\n\tscanf(\"%d\", &n);\n\tchar ** s = new char *[n];\n\tfor (i = 0; i < n; i++)\n\t{\n\t\ts[i] = new char[100];\n\t\tscanf(\"%s\", s[i]);\n\t\tchar * t = s[i];\n\t\twhile (*t != '\\0')\n\t\t{\n\t\t\tif (t == s[i] && (*t >= 'a' && *t <= 'z')) *t = *t - 'a' + 'A';\n\t\t\tif (t > s[i] && (*t >= 'A' && *t <= 'Z')) *t = *t - 'A' + 'a';\n\t\t\tt++;\n\t\t}\n\t}\n\tqsort(s, n, sizeof(char *), cmp);\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tprintf(\"%s\\n\", s[i]);\n\t}\n\treturn 0;\n}\n```\n\n\n\n```\n how many words?\n5\nwORd\nHellO\nyEllow\nshe\nAPPLE\nApple\nHello\nShe\nWord\nYellow\nPress any key to continue\n```\n\n", + "tag_name": "c语言", + "cpp": " #include \n#include \n#include \nint cmp(const void * a, const void * b)\n{\n\treturn strcmp(*(char **)a, *(char **)b);\n}\nint main(int argc, char* argv[])\n{\n\tint n = 0;\n\tint i;\n\tprintf(\"how many words?\\n\");\n\tscanf(\"%d\", &n);\n\tchar ** s = new char *[n];\n\tfor (i = 0; i < n; i++)\n\t{\n\t\ts[i] = new char[100];\n\t\tscanf(\"%s\", s[i]);\n\t\tchar * t = s[i];\n\t\twhile (*t != '\\0')\n\t\t{\n\t\t\tif (t == s[i] && (*t >= 'a' && *t <= 'z')) *t = *t - 'a' + 'A';\n\t\t\tif (t > s[i] && (*t >= 'A' && *t <= 'Z')) *t = *t - 'A' + 'a';\n\t\t\tt++;\n\t\t}\n\t}\n\tqsort(s, n, sizeof(char *), cmp);\n\tfor (i = 0; i < n; i++)\n\t{\n\t\tprintf(\"%s\\n\", s[i]);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470273", + "status": 1, + "keywords": "算法,排序", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/111.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/112.json b/data_backup/cpp_code_json/112.json new file mode 100644 index 000000000..bda3c7f90 --- /dev/null +++ b/data_backup/cpp_code_json/112.json @@ -0,0 +1,18 @@ +{ + "question_id": 7459909, + "question_title": "完数", + "question_content": "
一个数如果恰好等于它的所有因子之和,这个数就称为“完数”。统计自然数 1 — 100 间完数的个数。
", + "difficulty": "中等", + "answer_id": 53444950, + "answer_content": "

供参考:

\n\n
\n#include<stdio.h>\n\nint perfect()\n{\n    int i,x,sum,cnt=0;\n    for(i=1;i<=100;i++)\n    {\n        sum=0;\n        for(x=1;x<i;x++)\n        {\n            if(i%x==0)sum+=x;\n        }\n        if(i==sum)\n        {\n            cnt++;\n            printf("%d ",i);\n        }\n    }\n    return cnt;\n}\n\nint main()\n{\n    printf("\\ncount=%d\\n",perfect());\n    \n    return 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include\nint perfect()\n{\n\tint i,x,sum,cnt=0;\n\tfor(i=1;i<=100;i++)\n\t{\n\t\tsum=0;\n\t\tfor(x=1;x在主函数中随机生成一有n个元素的一维数组(元素的取值范围载10-90之间),调用排序函数对该数组进行排序,并输出排序结果。

", + "difficulty": "困难", + "answer_id": 53432910, + "answer_content": "
\n#include <stdio.h>\n#include <random>\n#include <iostream>\n#include <string>\n#include <time.h>\n\nusing namespace std;\n\nvoid InsertSort(int a[], int n)\n{\n\tfor (int i = 1; i<n; i++) {\n\t\tif (a[i] < a[i - 1]) {               //若第i个元素大于i-1元素,直接插入。小于的话,移动有序表后插入  \n\t\t\tint j = i - 1;\n\t\t\tint x = a[i];        //复制为哨兵,即存储待排序元素  \n\t\t\ta[i] = a[i - 1];           //先后移一个元素  \n\t\t\twhile (x < a[j]) {  //查找在有序表的插入位置  \n\t\t\t\ta[j + 1] = a[j];\n\t\t\t\tj--;         //元素后移  \n\t\t\t}\n\t\t\ta[j + 1] = x;      //插入到正确位置  \n\t\t}\n\t}\n}\n\nint main()\n{\n\tcout << "请输入产生多个随机数:";\n\tint ranNum[100],num = 0;\n\tsrand((unsigned)time(NULL));//time()用系统时间初始化种。为rand()生成不同的随机种子\n\tcin >> num;\n\tcout << "随机数组:";\n\tfor (int i = 0; i < num; i++)\n\t{\n\t\tranNum[i] = 10 + (rand() % 80);\n\t\tcout << " " << ranNum[i];\n\t}\n\tcout << endl;\n\tInsertSort(ranNum, num);\n\tcout << "排序后整数序列:";\n\tfor (int j = num-1; j >= 0; j--) {\n\t\tcout << ranNum[j] << " ";\n\t}\n\tcout << endl;\n\tsystem("pause");\n\treturn 0;\n}
\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \n#include \n#include \n#include \nusing namespace std;\nvoid InsertSort(int a[], int n)\n{\n\tfor (int i = 1; i> num;\n\tcout << \"随机数组:\";\n\tfor (int i = 0; i < num; i++)\n\t{\n\t\tranNum[i] = 10 + (rand() % 80);\n\t\tcout << \" \" << ranNum[i];\n\t}\n\tcout << endl;\n\tInsertSort(ranNum, num);\n\tcout << \"排序后整数序列:\";\n\tfor (int j = num-1; j >= 0; j--) {\n\t\tcout << ranNum[j] << \" \";\n\t}\n\tcout << endl;\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469961", + "status": 1, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/113.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/114.json b/data_backup/cpp_code_json/114.json new file mode 100644 index 000000000..2d7d5e499 --- /dev/null +++ b/data_backup/cpp_code_json/114.json @@ -0,0 +1,18 @@ +{ + "question_id": 7407528, + "question_title": "实现五则运算", + "question_content": "

设计一个可以完成任意五则运算(加法/减法/乘法/除法/取余)的程序。除法按照计算机中整型相除来计算。\n输入格式\n多行输入,每输入一行数据对应输出一行。\n每行输入格式为 a # b,其中 #∈{+,−,∗,/,%}\na,b均为自然数\n输出格式\n每行输出对应的计算结果;\n当运算为除法/取余的时候,如果除数为 0 ,输出 WA 。

\n

输入样例

\n
\n2+2\n4*5\n6/7\n4%3\n4%0
\n

输出样例

\n
\n4\n20\n0\n1\nWA
", + "difficulty": "简单", + "answer_id": 53357554, + "answer_content": "
\n#include<stdio.h>\n\nint main()\n{\n\tint a;\n\tint b;\n\tchar operation;\n\tint num;\n\n\twhile (scanf("%d", &a) != EOF)\n\t{\n\t\tscanf("%c", &operation);\n\t\tscanf("%d", &b);\n\n\t\tif (operation == '+')\n\t\t{\n\t\t\tnum = a + b;\n\t\t\tprintf("%d\\n", num);\n\t\t}\n\t\telse if (operation == '-') {\n\t\t\tnum = a - b;\n\t\t\tprintf("%d\\n", num);\n\t\t}\n\t\telse if (operation == '*') {\n\t\t\tnum = a * b;\n\t\t\tprintf("%d\\n", num);\n\t\t}\n\t\telse if (operation == '/' && b != 0) {\n\t\t\tnum = a / b;\n\t\t\tprintf("%d\\n", num);\n\t\t}\n\t\telse {\n\t\t\tprintf("%s\\n", "WA");\n\t\t}\n\t}\n\treturn 0;\n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint a;\n\tint b;\n\tchar operation;\n\tint num;\n\twhile (scanf(\"%d\", &a) != EOF)\n\t{\n\t\tscanf(\"%c\", &operation);\n\t\tscanf(\"%d\", &b);\n\t\tif (operation == '+')\n\t\t{\n\t\t\tnum = a + b;\n\t\t\tprintf(\"%d\\n\", num);\n\t\t}\n\t\telse if (operation == '-') {\n\t\t\tnum = a - b;\n\t\t\tprintf(\"%d\\n\", num);\n\t\t}\n\t\telse if (operation == '*') {\n\t\t\tnum = a * b;\n\t\t\tprintf(\"%d\\n\", num);\n\t\t}\n\t\telse if (operation == '/' && b != 0) {\n\t\t\tnum = a / b;\n\t\t\tprintf(\"%d\\n\", num);\n\t\t}\n\t\telse {\n\t\t\tprintf(\"%s\\n\", \"WA\");\n\t\t}\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470274", + "status": 1, + "keywords": "算法高阶,计算几何学,算法问题选编,确定任意一对线段是否相交", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/114.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/115.json b/data_backup/cpp_code_json/115.json new file mode 100644 index 000000000..2c9b97460 --- /dev/null +++ b/data_backup/cpp_code_json/115.json @@ -0,0 +1,18 @@ +{ + "question_id": 7442914, + "question_title": "最小花费", + "question_content": "

题目描述

乐乐做好了一二三等奖奖品费用预算方案之后,决定到市场上具体咨询一下三种奖品的具体价格,发现各个商家的报价还是有差别的,乐乐决定哪家所有奖品总金额最少就在哪家购买,假设每家货源是充足的。乐乐咨询了n个店家,几乎跑遍了整个市场,才得到各个商家的最低报价清单。现在请你计算出乐乐会在哪家商家购买奖品以及费用是多少。\n输入

共 n+1 行 

第一行,有四个整数 n,x,y,z,数与数之间用一个空格隔开,n 表示乐乐咨询的商家数,x,y,z 分别表示要购买一等奖奖品数量、二等奖奖品数量、三等奖奖品数量。 

接下来的 n 行,每行都有三个数,数与数之间用一个空格隔开,第 i+1 行分别表示编号为 i 的商家对一、二、三等奖奖品的报价(单价) \n输出

共有两个整数,第一个数表示购买奖品的商家编号(如果有多家总费用最少,输出编号最小的商家),第二个数是购买奖品的总费用。 \n样例输入

\n3 1 2 3\n70 50 30\n60 40 20\n80 55 33\n

样例输出

\n2 200

提示

【样例解释】

乐乐咨询了 3 个商家,打算购买一二三等奖奖品数量分别是 1 个、2 个、3 个,编号为 1 的商家一二三等奖奖品报价分别是 70、50、30 元,编号为 2 的商家报价分别是 60、40、20 元,编号为 3 的商家报价分别是 80、55、20 元,乐乐在编号为 2 的商家购买总费用最低,为200 元。

【数据范围】

40%数据:1≤n≤5000 

100%数据:1≤n≤100000,1≤x,y,z≤1000,奖品报价都是 1000 范围以内的正整数。

", + "difficulty": "困难", + "answer_id": 53419944, + "answer_content": "
\n#include <iostream>\n#include <stdio.h>\nusing namespace std;\n\nint main(){\n    int n,x,y,z,i,min=1000000,n1,n2,n3,temp,t=0;\n    cin>>n>>x>>y>>z;\n    for(i=0;i<n;i++){\n        temp=0;\n        cin>>n1>>n2>>n3;\n        temp+=n1*x+n2*y+n3*z;\n        if(temp<min){\n            min=temp;\n            t=i+1;\n        }\n    }\n    cout<<t<<" "<<min;\n    return 0;\n}
\n\n

\"\"

\n", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint main(){\n\tint n,x,y,z,i,min=1000000,n1,n2,n3,temp,t=0;\n\tcin>>n>>x>>y>>z;\n\tfor(i=0;i>n1>>n2>>n3;\n\t\ttemp+=n1*x+n2*y+n3*z;\n\t\tif(temp请编写一个fun函数,实现如下功能:将一个字符串中第一个连续数字转换成整数,作为函数值返回,否则返回0(程序的输入输出要有提示)\n比如:字符串中的内容为:"abc123 def45gh",则函数的返回值为123。

", + "difficulty": "中等", + "answer_id": 53406098, + "answer_content": "

为什么不写注释?

\n\n

懒得写。。。 

\n\n
\n#include <iostream>\n#include <string>\n\nusing namespace std;\n\nint fun(string str);\n\nint main(void) {\n\tstring str = "abc123 def45gh";\n\n\tcout << fun(str);\n\n\n\treturn 0;\n}\n\n\nint fun(string str) {\n\tint index = -1;\n\tint score = 0;\n\n\tfor (int i = 0; i < str.length(); i++) {\n\t\tif ((str[i] >= 48 && str[i] <= 57) && (i + 1 < str.length()) && (str[i + 1] >= 48 && str[i + 1] <= 57)) {\n\t\t\tindex = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (index == -1) {\n\t\treturn score;\n\t}\n\n\tscore = str[index] - '0';\n\tfor (int i = index + 1; i < str.length(); i++) {\n\t\tif (str[i] >= 48 && str[i] <= 57) {\n\t\t\tscore *= 10;\n\t\t\tscore += str[i] - '0';\n\t\t\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn score;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nusing namespace std;\nint fun(string str);\nint main(void) {\n\tstring str = \"abc123 def45gh\";\n\tcout << fun(str);\n\treturn 0;\n}\nint fun(string str) {\n\tint index = -1;\n\tint score = 0;\n\tfor (int i = 0; i < str.length(); i++) {\n\t\tif ((str[i] >= 48 && str[i] <= 57) && (i + 1 < str.length()) && (str[i + 1] >= 48 && str[i + 1] <= 57)) {\n\t\t\tindex = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (index == -1) {\n\t\treturn score;\n\t}\n\tscore = str[index] - '0';\n\tfor (int i = index + 1; i < str.length(); i++) {\n\t\tif (str[i] >= 48 && str[i] <= 57) {\n\t\t\tscore *= 10;\n\t\t\tscore += str[i] - '0';\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn score;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469963", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/116.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/117.json b/data_backup/cpp_code_json/117.json new file mode 100644 index 000000000..6dafe0827 --- /dev/null +++ b/data_backup/cpp_code_json/117.json @@ -0,0 +1,18 @@ +{ + "question_id": 222425, + "question_title": "字符图形输出", + "question_content": "编程实现把输入任意整数n后,可打印出n行三角字符阵列图形。例如,输入整数5时,程序运行结果如下:\nENTER A NUMBER:5<回车>\nA C F J O\nB E I N\nD H M\nG L\nK", + "difficulty": "中等", + "answer_id": 178405, + "answer_content": "\n\n```\n #include \nusing namespace std;\n\nchar a[100][100];\n\nint main()\n{\n char c = 'A';\n int n = 5;\n for (int i = 0; i < n; i++)\n {\n for (int j = i; j >= 0; j--)\n {\n a[j][i - j] = c++;\n }\n }\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n - i; j++)\n {\n cout << a[i][j] << \" \";\n }\n cout << endl;\n }\n}\n```\n\n", + "tag_name": "c++", + "cpp": " #include \nusing namespace std;\nchar a[100][100];\nint main()\n{\n\tchar c = 'A';\n\tint n = 5;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tfor (int j = i; j >= 0; j--)\n\t\t{\n\t\t\ta[j][i - j] = c++;\n\t\t}\n\t}\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tfor (int j = 0; j < n - i; j++)\n\t\t{\n\t\t\tcout << a[i][j] << \" \";\n\t\t}\n\t\tcout << endl;\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469861", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/117.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/118.json b/data_backup/cpp_code_json/118.json new file mode 100644 index 000000000..18df86b92 --- /dev/null +++ b/data_backup/cpp_code_json/118.json @@ -0,0 +1,18 @@ +{ + "question_id": 1078333, + "question_title": "从用户处输入5人2个整数排列a、b,并检查对应的排列要素是否相同。", + "question_content": "

使用array_equal(int a[],int b[],int size)\na[0]和b[0],a[1]和b[1],…,a[size-1]和b[size-1]检查是否相同\n如果整体要素相同,则返还1,否则返还0。\n利用反复循环检查排列的各要素是否相等。如果有一个不同的地方,就可以马上返还0。![图片说明](https://img-ask.csdn.net/upload/202005/28/1590646351_294989.png)\n翻译是:\n输入第一次排列:1 2 3 4 5\n输入第二次排列:1 2 2 2 2 \n不一致返还0\n第二个一致就返还1

", + "difficulty": "中等", + "answer_id": 1282702, + "answer_content": "\n```\n#include\n\nint main()\n{\n\tint a[5], b[5], i;\n\tprintf(\"输入5个数:\");\n\tfor(i = 0; i < 5; i++)\n\t\tscanf(\"%d\", &a[i]);\n\tfor(i = 0; i < 5; i++)\n\t\tscanf(\"%d\", &b[i]);\n\tfor(i = 0; i < 5; i++)\n\t\tif(a[i] != b[i])\n\t\t\tbreak;\n\tif(i==4)\n\t\tprintf(\"1\");\n\telse\n\t\tprintf(\"0\");\n\treturn 0;\n}\n```", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint a[5], b[5], i;\n\tprintf(\"输入5个数:\");\n\tfor(i = 0; i < 5; i++)\n\t\tscanf(\"%d\", &a[i]);\n\tfor(i = 0; i < 5; i++)\n\t\tscanf(\"%d\", &b[i]);\n\tfor(i = 0; i < 5; i++)\n\t\tif(a[i] != b[i])\n\t\t\tbreak;\n\tif(i==4)\n\t\tprintf(\"1\");\n\telse\n\t\tprintf(\"0\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469862", + "status": 0, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/118.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/119.json b/data_backup/cpp_code_json/119.json new file mode 100644 index 000000000..c1f8432c8 --- /dev/null +++ b/data_backup/cpp_code_json/119.json @@ -0,0 +1,17 @@ +{ + "question_id": 3368121, + "question_title": "计算一下函数的值", + "question_content": "

计算s=1+(1+2)+(1+2+3)+……+(1+2+3+……+n)的值

\n\n

当某一项的值超过50时,结束循环,并将当时的s的值进行输出,将当时刚好超过50的那一项的值和项数一并输出;

\n\n

如果最终项的值没有超过50,则按循环计划计算完所有的累加和,也将最终项的值和项数一并输出。  

", + "difficulty": "简单", + "answer_id": 22392963, + "answer_content": "

#include<stdio.h>
\n#include<math.h>
\n#include<string.h>
\n#include<stdlib.h>
\nint main(int argc,char * argv[])
\n{
\n        int summer,summer2,num;//声明和与项数变量
\n        summer=0,summer2=0;//初始化和变量
\n        num=atoi(argv[1]);//将命令行第二个参数转化为整数项数
\n        for(int i=1;i<=num;i++)//进行循环求和
\n        {
\n                summer+=i;
\n                summer2+=summer;
\n                if(summer>50)//当某一项的值大于50时
\n                {
\n                        printf("计算总和是%d\\n超过50的项是第%d项\\n",summer2,i);
\n                        printf("该项的值是%d\\n",summer);
\n                        return 0;
\n                }

\n\n

        }
\n        printf("计算总和是%d\\n,最后一项是%d\\n没有任何一项的值超过50\\n",summer2,num);//当任一一项的值均不大于50时
\n        return 0;
\n       

\n\n

}

\n\n


\n代码编译运行正确无误,使用格式为:×××.exe    number。***.exe指本地编译成的程序,number是要循环计算的项数。二者之间有一个空格。如果我对题目的理解有误,请私信我或者评论处给我留言。

", + "tag_name": "c语言", + "cpp": "#include\n#include\n#include\n#include\nint main(int argc,char * argv[])\n{\n        int summer,summer2,num;\n        summer=0,summer2=0;\n        num=atoi(argv[1]);\n        for(int i=1;i<=num;i++)\n        {\n                summer+=i;\n                summer2+=summer;\n                if(summer>50)\n                {\n                        printf(\"计算总和是%d\\n超过50的项是第%d项\\n\",summer2,i);\n                        printf(\"该项的值是%d\\n\",summer);\n                        return 0;\n                }\n        }\n        printf(\"计算总和是%d\\n,最后一项是%d\\n没有任何一项的值超过50\\n\",summer2,num);\n        return 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470275", + "status": 0, + "keywords": "算法高阶,计算几何学,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/119.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/12.json b/data_backup/cpp_code_json/12.json new file mode 100644 index 000000000..a367b212e --- /dev/null +++ b/data_backup/cpp_code_json/12.json @@ -0,0 +1,18 @@ +{ + "question_id": 7452215, + "question_title": "由数值大小在闭区间的", + "question_content": "

创建一个大小为 100 的整型数组,数组元素由数值大小在闭区间[0,1000]内的\n随机数组成。在控制台窗口中输出数组内数值为 7 的倍数,且除以 3 余数为 2 的\n元素。若数组中不存在符合规则的元素,则在控制台中给出相应提示

", + "difficulty": "简单", + "answer_id": 53434106, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n#include <stdlib.h>\nint main()\n{\n\tint a[100];\n\tint i,nmb = 0;\n\tfor(i = 0;i<100;i++)\n\t\ta[i] = rand()%1000;\n\tfor (i = 0;i<100;i++)\n\t{\n\t\tif( (a[i]%7 == 0) && (a[i]%3 ==2) )\n\t\t{\n\t\t\tprintf("%5d",a[i]);\n\t\t\tnmb++;\n\t\t}\n\t}\n\tprintf("\\n");\n\tif(nmb == 0)\n\t\tprintf("没有符合条件的数\\n");\n\t\n\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tint a[100];\n\tint i,nmb = 0;\n\tfor(i = 0;i<100;i++)\n\t\ta[i] = rand()%1001;\n\tfor (i = 0;i<100;i++)\n\t{\n\t\tif( (a[i]%7 == 0) && (a[i]%3 ==2) )\n\t\t{\n\t\t\tprintf(\"%5d\",a[i]);\n\t\t\tnmb++;\n\t\t}\n\t}\n\tprintf(\"\\n\");\n\tif(nmb == 0)\n\t\tprintf(\"没有符合条件的数\\n\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469937", + "status": 1, + "keywords": "区间树,算法中阶,数据结构,数据结构的扩张", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/12.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/120.json b/data_backup/cpp_code_json/120.json new file mode 100644 index 000000000..12354d11d --- /dev/null +++ b/data_backup/cpp_code_json/120.json @@ -0,0 +1,18 @@ +{ + "question_id": 3082820, + "question_title": "逆序存放数组中的数据,并输出指定元素", + "question_content": "

将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按要求输出指定的数组元素。\n输入格式:\n在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。第三行输入一个非负整数m(m<n)。\n输出格式:\n在一行中输出逆序存放后下标为m的数组元素。行末无空格。

\n输入样例:

\n
\n6\n10 8 1 2 3 4\n2
\n

输出样例:

\n
\n2
", + "difficulty": "中等", + "answer_id": 19384015, + "answer_content": "
\n#include <stdio.h>\n#include <stdlib.h>\n\nint main()\n{\n    int n,m;\n    scanf("%d",&n);\n    if(n<1||n>10){\n       printf("1≤n≤10");\n       return 0;\n    }\n    int *a = (int*)malloc(sizeof(int)*n);\n    for(int i=n-1; i>=0; i-- ){\n        scanf("%d",&a[i]);\n    }\n    scanf("%d",&m);\n    if(m<0||m>=n){\n       printf("0≤m<n");\n       return 0;\n    }\n    printf("%d",a[m]);  \n    return 0;\n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tint n,m;\n\tscanf(\"%d\",&n);\n\tif(n<1||n>10){\n\t printf(\"1≤n≤10\");\n\t return 0;\n\t}\n\tint *a = (int*)malloc(sizeof(int)*n);\n\tfor(int i=n-1; i>=0; i-- ){\n\t\tscanf(\"%d\",&a[i]);\n\t}\n\tscanf(\"%d\",&m);\n\tif(m<0||m>=n){\n\t printf(\"0≤m【问题描述】规定26个英文字符的能量值分别是1-26,键盘输入一个英文单词,输出它的能量值。字符不区分大小写。\n【输入形式】在提示语后面输入一个单词\n【输出形式】输出energy=计算值\n【样例输入1】Input a word:Integrity\n【样例输出1】energy=127\n【样例输入2】Input a word:Upset\n【样例输出2】energy=81\n【样例说明】下划线上是输入输出的数据,其余是程序的提示信息

", + "difficulty": "简单", + "answer_id": 53396246, + "answer_content": "
\n#include <stdio.h>\n#include <string>\nusing namespace std;\n#pragma warning(disable:4996)\nint  main()\n{\n\tint i;\n\tint sum = 0;\n\tchar arrs[1000];\n\tprintf("Input a word:");\n\twhile (scanf("%s", &arrs) != EOF) {\n\t\tsum = 0;\n\t\tfor (i = 0; i < strlen(arrs); i++) {\n\t\t\t/// <summary>\n\t\t\t/// a-z 的ascii码高于 A-Z\n\t\t\t/// </summary>\n\t\t\t/// <returns></returns>\n\t\t\tif (arrs[i] > 'a') {\n\t\t\t\tsum += arrs[i] - 'a' + 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsum += arrs[i] - 'A' + 1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tprintf("energy=%d\\n", sum);\n\t\tprintf("Input a word:");\n\t\t\n\t}\n\t\n\treturn 0;\n}
\n\n

 \"\"

\n\n

程序运行结果:

\n\n
\nInput a word:Integrity\nenergy=127\nInput a word:Upset\nenergy=81\nInput a word:
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nusing namespace std;\n#pragma warning(disable:4996)\nint main()\n{\n\tint i;\n\tint sum = 0;\n\tchar arrs[1000];\n\tprintf(\"Input a word:\");\n\twhile (scanf(\"%s\", &arrs) != EOF) {\n\t\tsum = 0;\n\t\tfor (i = 0; i < strlen(arrs); i++) {\n\t\t\tif (arrs[i] >= 'a') {\n\t\t\t\tsum += arrs[i] - 'a' + 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsum += arrs[i] - 'A' + 1;\n\t\t\t}\n\t\t}\n\t\tprintf(\"energy=%d\\n\", sum);\n\t\tprintf(\"Input a word:\");\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469864", + "status": 1, + "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/121.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/122.json b/data_backup/cpp_code_json/122.json new file mode 100644 index 000000000..c5e0da249 --- /dev/null +++ b/data_backup/cpp_code_json/122.json @@ -0,0 +1,18 @@ +{ + "question_id": 1049165, + "question_title": "数组元素循环右移问题", + "question_content": "题目:一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?\n输入格式:\n每个输入包含一个测试用例,第1行输入N(1≤N≤100)和M(≥0);第2行输入N个整数,之间用空格分隔。\n输出格式:\n在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。\n输入样例:\n\t6 2\n\t1 2 3 4 5 6\n输出样例:\n\t5 6 1 2 3 4\n", + "difficulty": "简单", + "answer_id": 1246646, + "answer_content": "6 7\n1 2 3 4 5 6\n这个输出应该是\n6 1 2 3 4 5\n你的是\n1 2 3 4 5 6\n\n这样写\n\n```\n#include\nint main()\n{\n int n,m,a[1000];\n scanf(\"%d %d\",&n,&m);\n m = m % n;\n int count=m;\n while(m\nint main()\n{\n\tint n,m,a[1000];\n\tscanf(\"%d %d\",&n,&m);\n\tm = m % n;\n\tint count=m;\n\twhile(m每位同学都有自己的一个幸运数,乐乐所在班级共有n位同学,因此有编号为1至n的n块标牌,标牌的编号与自己的幸运数相乘,就是这位同学的分数。你的工作就是帮乐乐寻找一种方案,使得班级总分数最大。\n输入\n第一行只有一个整数n\n第二行共有n个不超过10000的正整数,中间有一个空格隔开。\n输出\n只有一行且只有一个整数,乐乐班级的总分数。

", + "difficulty": "简单", + "answer_id": 53400440, + "answer_content": "
\n#include<stdio.h>\nint main()\n{\n    int a[10005];\n    long long t=0;\n\tint n,i,j,x;\n\tscanf("%d",&n);\n\tfor(i=0;i<n;i++)\n\t    scanf("%d",&a[i]);\n\tfor(i=0;i<n;i++){\n        for(j=0;j<n;j++){\n            if(a[i]>a[j]){\n                x=a[i];\n                a[i]=a[j];\n                a[j]=x;\n            }\n        }\n\t}\n\tfor(i=0;i<n;i++)\n\t{\n\t\tt+=a[i]*(i+1);\n\t}\n\tprintf("%lld",t);\n\treturn 0;\n}\n
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint a[10005];\n\tlong long t=0;\n\tint n,i,j,x;\n\tscanf(\"%d\",&n);\n\tfor(i=0;ia[j]){\n\t\t\t\tx=a[i];\n\t\t\t\ta[i]=a[j];\n\t\t\t\ta[j]=x;\n\t\t\t}\n\t\t}\n\t}\n\tfor(i=0;i\n#include<iostream>\n#include<algorithm>\nusing namespace std;\nint main()\n{\n char ans[4]={'A','B','C','D'};\n sort(ans,ans+4); /* 这个sort可以不用,因为{1,2,3,4}已经排好序*/\n do /*注意这步,如果是while循环,则需要提前输出*/\n {\n for(int i=0;i<4;++i)\n cout<<ans[i]<<" ";\n cout<<endl;\n }while(next_permutation(ans,ans+4));\n return 0;\n}\n\n

 去判断吧。

\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include\n#include\nusing namespace std;\nint main()\n{\n\tchar ans[4]={'A','B','C','D'};\n\tsort(ans,ans+4);\t\n\tdo\t\t\t\t\t\t\t \n\t{\n\t\tfor(int i=0;i<4;++i)\n\t\t\tcout<。\n输出:B在第2个位置,其后面第四个字母是F", + "difficulty": "简单", + "answer_id": 1273628, + "answer_content": "\n```\n#include \n\nint main(){\n char c,c2;\n printf(\"输入:\");\n c = getchar();\n int m=0,n=0;\n if(c>='A'&& c<='z')\n {\n m = c - 'A' + 1;\n if(m < 23)\n {\n c2 = c + 4;\n n = m+4;\n }\n }\n if(n > 0)\n printf(\"%c在第%d个位置,其后面第四个字母是%c\\n\",c,m,c2);\n else\n printf(\"%c在第%d个位置,其后面没有第四个字母\\n\",c,m);\n return 0;\n}\n```", + "tag_name": "c语言", + "cpp": "#include \nint main(){\n\tchar c,c2;\n\tprintf(\"输入:\");\n\tc = getchar();\n\tint m=0,n=0;\n\tif(c>='A'&& c<='z')\n\t{\n\t\tm = c - 'A' + 1;\n\t\tif(m < 23)\n\t\t{\n\t\t\tc2 = c + 4;\n\t\t\tn = m+4;\n\t\t}\n\t}\n\tif(n > 0)\n\t\tprintf(\"%c在第%d个位置,其后面第四个字母是%c\\n\",c,m,c2);\n\telse\n\t\tprintf(\"%c在第%d个位置,其后面没有第四个字母\\n\",c,m);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470277", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/125.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/126.json b/data_backup/cpp_code_json/126.json new file mode 100644 index 000000000..5e1002c44 --- /dev/null +++ b/data_backup/cpp_code_json/126.json @@ -0,0 +1,17 @@ +{ + "question_id": 7400042, + "question_title": "魔法少女锦姐姐", + "question_content": "锦姐姐作为魔法少女有很多魔法石,每个魔法石都有一个符文,符文是一个数字。\n \n 锦姐姐想知道她拥有某一种魔法石的数量。\n \n \n \n \n 输入\n \n \n 第一行输入一个数t,代表有t组数据\n \n 每组数据的第一行输入两个数n,q,代表n个魔法石,q次询问\n \n 接下来一行n个整数ai,表示每个魔法石的符文\n \n 接下来q行,每行一个数x,代表符文为x\n \n 数据范围:1<=t<=100,1<=n<=100000,1<=q<=1000,0<=ai<=100000,0<=x<=100000\n \n \n 输出\n \n \n 每组输出q行\n \n 每行输出符文为x的魔法石的个数\n \n \n 样例输入Copy\n \n \n1\n5 2\n1 1 2 2 3\n2\n3 \n \n 样例输出Copy\n \n \n2\n1 ", + "difficulty": "困难", + "answer_id": 53347760, + "answer_content": "

我帮你改良了一下,试试我这个代码

\n\n
\n#include<stdio.h>\n#include<string.h>\nint a[100001];\nint main()\n{\n    int t,i,n,q,x,y;\n    scanf("%d",&t);\n    while(t--)\n    {\n\t\tmemset(a,0,sizeof(a));\n        scanf("%d %d",&n,&q);\n        for(i=0;i<n;i++)\n\t\t{\n            scanf("%d",&y);\n\t\t\ta[y]++;\n\t\t }\n            while(q--)\n            {\n                scanf("%d",&x);\n                printf("%d\\n",a[x]);\n            }\n    }\n    return 0;\n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\n#include\nint a[100001];\nint main()\n{\n\tint t,i,n,q,x,y;\n\tscanf(\"%d\",&t);\n\twhile(t--)\n\t{\n\t\tmemset(a,0,sizeof(a));\n\t\tscanf(\"%d %d\",&n,&q);\n\t\tfor(i=0;i代码修改如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n#include <stdlib.h>\nint main()\n{\n\tint n,i,j,t;\n\t\n\tscanf("%d",&n);\n\tint* a = (int*)malloc(n*sizeof(int));\n\tfor(i=0;i<n;i++)\n\t{\n\t\tscanf("%d",&a[i]);\n\t}\n\tint cout=0;\n\tfor( i=0;i<n;i++)\n\t{ \n\t\tfor( j=i+1;j<n;j++)\n\t\t{\n\t\t\tfor(t = 0; t <n;t++)\n\t\t\t\tif(a[i]+a[j]==a[t])\n\t\t\t\t\tcout++;\n\t\t}\n\t}\n\tprintf("%d",cout);\n\tfree(a);\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tint n,i,j,t;\n\tscanf(\"%d\",&n);\n\tint* a = (int*)malloc(n*sizeof(int));\n\tfor(i=0;i

题目描述\n植树节又到了,商家A和商家B为了卖出更多的树苗。
\n商家A有了新的决定:
\n购买树苗数量小于等于10棵,所有树苗按正常价格10元一棵收费;
\n购买树苗数量大于10且小于等于20棵,超出10棵以上的树苗按8.2元一棵收费,其余树苗按正常价格收费;
\n购买树苗数量大于20棵,超出20棵以上的树苗按7.5元一棵收费,10至20棵部分树苗按8.2元一棵收费,其余树苗按正常价格收费。
\n商家B决定:
\n所有树苗12元一棵,但是均打七折卖出。

图图要代表班级去买树苗,要求输入图图需要购买的树苗棵数,输出在哪家商家购买更加划算及其所要花费的钱数。\n输入要求\n1 行,一个整数,表示图图需要购买的树苗数量。\n输出要求\n1 行,如果商家A的树苗比较划算,输出:A,否则输出:B,同时输出图图购买树苗最优惠的钱数(文字和数字间用空格隔开)。
\n样例输入

\n
\n30
\n

样例输出 

\n
\nB 252
", + "difficulty": "中等", + "answer_id": 53347698, + "answer_content": "

修改数据类型int为double。在计算过程中多是浮点计算,所以如果使用int系统会对计算结果进行取整,多次执行会有误差

\n\n
\n#include <iostream>\nusing namespace std;\nint main() {\n    double n, A, B;    //数据类型用double,保证计算精度\n    cin >> n;\n    B = 12 * 0.7 * n;\n    if (n <= 10) {\n        A = 10 * n;\n    }\n    else if (n > 10 && n <= 20) {\n        A = 10 * 10 + (n - 10) * 8.2;\n    }\n    else {\n        A = 10 * 8.2 + (n - 20) * 7.5 + 10 * 10;\n    }\n    if (A < B) {\n        cout << "A " << A;\n    }\n    else {\n        cout << "B " << B;\n    }\n    return 0;\n}
\n\n

 

", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint main() {\n\tdouble n, A, B;\t\n\tcin >> n;\n\tB = 12 * 0.7 * n;\n\tif (n <= 10) {\n\t\tA = 10 * n;\n\t}\n\telse if (n > 10 && n <= 20) {\n\t\tA = 10 * 10 + (n - 10) * 8.2;\n\t}\n\telse {\n\t\tA = 10 * 8.2 + (n - 20) * 7.5 + 10 * 10;\n\t}\n\tif (A < B) {\n\t\tcout << \"A \" << A;\n\t}\n\telse {\n\t\tcout << \"B \" << B;\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469866", + "status": 1, + "keywords": "图算法,算法高阶,图的表示,基本的图算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/128.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/129.json b/data_backup/cpp_code_json/129.json new file mode 100644 index 000000000..b7e4626d5 --- /dev/null +++ b/data_backup/cpp_code_json/129.json @@ -0,0 +1,18 @@ +{ + "question_id": 7446099, + "question_title": "找出string中只出现过一次的字符", + "question_content": "找出string中只出现过一次的字符\n例如\"abcdef abcd\"中需要得到ef", + "difficulty": "简单", + "answer_id": 53425698, + "answer_content": "

#include <iostream>
\n#include <string>

\n\n

using namespace std;

\n\n

int main()
\n{
\n    string temp = "";
\n    cout << "请输入字符串:";
\n    cin >> temp;
\n    string str = "";        //存放只出现一次的字符
\n    string str1 = "";        //存放重复的字符
\n    for (int i = 0; i < temp.length(); i++)
\n    {
\n        string tempSub = temp.substr(i, 1);    
\n        int b = temp.rfind(tempSub);                //从后向前查找字符出现的位置
\n        if (i == b && str1.find(tempSub) == -1)        //如果b和遍历查找的位置一致,且str1 里没有该字符,说明只出现一次
\n            str +=temp.substr(i, 1);
\n        else if (str1.find(tempSub) == -1)
\n            str1 += temp.substr(i, 1);;
\n    }
\n    cout << "只出现一次的字符:" << str << endl;
\n    cout << "重复出现的字符的字符:" << str1 << endl;
\n    system("pause");
\n    return 0;
\n}

\n\n

\"\"

\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint main()\n{\n    string temp = \"\";\n    cout << \"请输入字符串:\";\n    cin >> temp;\n    string str = \"\";        \n    string str1 = \"\";        \n    for (int i = 0; i < temp.length(); i++)\n    {\n        string tempSub = temp.substr(i, 1);    \n        int b = temp.rfind(tempSub);                \n        if (i == b && str1.find(tempSub) == -1)        \n            str +=temp.substr(i, 1);\n        else if (str1.find(tempSub) == -1)\n            str1 += temp.substr(i, 1);\n    }\n    cout << \"只出现一次的字符:\" << str << endl;\n    cout << \"重复出现的字符的字符:\" << str1 << endl;\n    system(\"pause\");\n    return 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470278", + "status": 1, + "keywords": "算法,字符串", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/129.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/13.json b/data_backup/cpp_code_json/13.json new file mode 100644 index 000000000..4dca353d5 --- /dev/null +++ b/data_backup/cpp_code_json/13.json @@ -0,0 +1,18 @@ +{ + "question_id": 1090014, + "question_title": "有序表的折半查找", + "question_content": "问题描述:\n用有序表表示静态查找表时,通常检索函数可以用折半查找来实现。\n折半查找的查找过程是:首先确定待查记录所在的范围,然后逐步缩小范围直到找到或者确定找不到相应的记录为止。而每次需要缩小的范围均为上一次的一半,这样的查找过程可以被称为折半查找。 \n第二行包含n个用空格隔开的正整数,表示n个有序的整数。输入保证这n个整数是从小到大递增的。\n第三行包含k个用空格隔开的正整数,表示k次查询的目标。\n输出:\n只有1行,包含k个整数,分别表示每一次的查询结果。如果在查询中找到了对应的整数,则输出其相应的位置,否则输出-1。\n请在每个整数后输出一个空格,并请注意行尾输出换行。", + "difficulty": "困难", + "answer_id": 1296683, + "answer_content": "\n```\n#include \n\nint binary( int *a, int key, int n )\n{\n int left = 0, right = n - 1, mid = 0;\n mid = ( left + right ) / 2;\n while( left < right && a[mid] != key )\n {\n if( a[mid] < key )\n left = mid + 1;\n else if( a[mid] > key )\n right = mid - 1;\n mid = ( left + right ) / 2;\n }\n if( a[mid] == key ) return mid;\n return -1;\n}\n\nint main (void)\n{\n int Base_a[20] = {1,3,5,8,9,40,120,123,125,150,199,200,1250,1255,1900,2000,2001,3000,3950,5000};\n\tint Search_a[5] = {12,199,9,2001,3500};\n\t\n\tint result = 0x00;\n\n\tfor(int i = 0;i < sizeof(Search_a)/sizeof(Search_a[0]);i++)\n\t{\n\t\tresult = binary(Base_a,Search_a[i],sizeof(Base_a)/sizeof(Base_a[0]));\n\t\tprintf(\"[%d %d] \",Search_a[i],result);\n\t}\n\tprintf(\"\\n\");\n\t\n\treturn 0;\n}\n```", + "tag_name": "c语言", + "cpp": "#include \nint binary( int *a, int key, int n )\n{\n\tint left = 0, right = n - 1, mid = 0;\n\tmid = ( left + right ) / 2;\n\twhile( left < right && a[mid] != key )\n\t{\n\t\tif( a[mid] < key )\n\t\tleft = mid + 1;\n\t\telse if( a[mid] > key )\n\t\tright = mid - 1;\n\t\tmid = ( left + right ) / 2;\n\t}\n\tif( a[mid] == key ) return mid;\n\treturn -1;\n}\nint main (void)\n{\n\tint Base_a[20] = {1,3,5,8,9,40,120,123,125,150,199,200,1250,1255,1900,2000,2001,3000,3950,5000};\n\tint Search_a[5] = {12,199,9,2001,3500};\n\tint result = 0x00;\n\tfor(int i = 0;i < sizeof(Search_a)/sizeof(Search_a[0]);i++)\n\t{\n\t\tresult = binary(Base_a,Search_a[i],sizeof(Base_a)/sizeof(Base_a[0]));\n\t\tprintf(\"[%d %d] \",Search_a[i],result);\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470249", + "status": 1, + "keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/13.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/130.json b/data_backup/cpp_code_json/130.json new file mode 100644 index 000000000..4773ec698 --- /dev/null +++ b/data_backup/cpp_code_json/130.json @@ -0,0 +1,18 @@ +{ + "question_id": 7428827, + "question_title": "报数游戏", + "question_content": "

题目描述
报数游戏\n首先,会给他们一人一个编号,并且每个人的编号都不相同。接下来的每一回合,会给一个数,编号超过它的最小编号的人要报出自己的编号。如果没有人的编号比给出的数要大,那么编号最大的人要报出自己的编号。每个人可以重复报号。\n会按照一个列表顺次报出每个回合的数,朋友们想知道每回合报出的编号应该是多少。\n输入
输入数据共 3 行。\n第一行有两个整数 n,m(1≤n≤100,000,1≤m≤100,000),分别表示参与游戏的朋友的个数,和游戏的回合数。 \n第二行 n个整数 ai(1≤ai≤100,000,000),表示朋友们每个人的编号。对于 0≤i<j<n,都有 ai<aj,即他们的编号递增排列。 \n第三行 m 个整数 qi(1≤qi≤100,000,000),表示每回合给的数字。\n输出
\n输出共一行 m 个整数,表示每回合报出的编号,每两个整数之间一个空格,最后一个数后面没有空格。

", + "difficulty": "中等", + "answer_id": 53395178, + "answer_content": "
\n#include<iostream>\n#include<cstring>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nint ai[100010], qi[100010];\nint main()\n{\n\tint a, q;\n\twhile (cin >> a >> q)\n\t{\n\t\tfor (int i = 0; i < a; i++)cin >> ai[i];\n\t\tfor (int i = 0; i < q; i++)cin >> qi[i];\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tint left = 0, right = a - 1, mid;\n\t\t\twhile (left < right) {\n\t\t\t\tmid = (left + right) >> 1;\n\t\t\t\tif (ai[mid] <= qi[i])left = mid + 1;\n\t\t\t\telse right = mid;\n\t\t\t}\n\t\t\tif (left - 1 < 0 || ai[left] < qi[i])left++;//qi[i]小于最小值或大于最大值的情况\n\t\t\ti ? cout << " " << ai[left - 1] : cout << ai[left - 1];\t\t\t\n\t\t}\n\t\tcout << endl;\n\t}\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include\n#include\n#include\n#include\nusing namespace std;\nint ai[100010], qi[100010];\nint main()\n{\n\tint a, q;\n\twhile (cin >> a >> q)\n\t{\n\t\tfor (int i = 0; i < a; i++)cin >> ai[i];\n\t\tfor (int i = 0; i < q; i++)cin >> qi[i];\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tint left = 0, right = a - 1, mid;\n\t\t\twhile (left < right) {\n\t\t\t\tmid = (left + right) >> 1;\n\t\t\t\tif (ai[mid] <= qi[i])left = mid + 1;\n\t\t\t\telse right = mid;\n\t\t\t}\n\t\t\tif (left - 1 < 0 || ai[left] < qi[i])left++;\n\t\t\ti ? cout << \" \" << ai[left - 1] : cout << ai[left - 1];\t\t\t\n\t\t}\n\t\tcout << endl;\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469965", + "status": 1, + "keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/130.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/131.json b/data_backup/cpp_code_json/131.json new file mode 100644 index 000000000..18632ba56 --- /dev/null +++ b/data_backup/cpp_code_json/131.json @@ -0,0 +1,18 @@ +{ + "question_id": 1003780, + "question_title": "计算位于矩阵边缘的元素之和", + "question_content": "描述\n输入一个整数矩阵,计算位于矩阵边缘的元素之和。所谓矩阵边缘的元素,就是第一行和最后一行的元素以及第一列和最后一列的元素。\n输入\n第一行分别为矩阵的行数m和列数n(m < 100,n < 100),两者之间以一个空格分开。\n接下来输入的m行数据中,每行包含n个整数,整数之间以一个空格分开。\n输出\n输出对应矩阵的边缘元素和\n样例输入\n3 3\n3 4 1\n3 7 1\n2 0 1\n样例输出\n15", + "difficulty": "简单", + "answer_id": 1184126, + "answer_content": "1 1\n1\n2Press any key to continue . . ..\n你这个用例不行,应该是1\n\n\n```\n#include\nint main()\n{\n int a[256][256];\n int n,m,i,j,sum=0;\n scanf(\"%d %d\",&n,&m);\n for(i=1;i<=n;i++)\n {\n for(j=1;j<=m;j++)\n {\n scanf(\"%d\",&a[i][j]);\n\t\t\tif (i == 1 || i == n || j == 1 || j == m) sum += a[i][j];\n }\n }\n printf(\"%d\",sum);\n return 0;\n}\n```", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint a[256][256];\n\tint n,m,i,j,sum=0;\n\tscanf(\"%d %d\",&n,&m);\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tfor(j=1;j<=m;j++)\n\t\t{\n\t\t\tscanf(\"%d\",&a[i][j]);\n\t\t\tif (i == 1 || i == n || j == 1 || j == m) sum += a[i][j];\n\t\t}\n\t}\n\tprintf(\"%d\",sum);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470181", + "status": 1, + "keywords": "算法高阶,矩阵运算,矩阵求逆,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/131.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/132.json b/data_backup/cpp_code_json/132.json new file mode 100644 index 000000000..fcbba1ca6 --- /dev/null +++ b/data_backup/cpp_code_json/132.json @@ -0,0 +1,18 @@ +{ + "question_id": 220434, + "question_title": "找出字符串中出现最多的字母", + "question_content": "Description\n钟Sir是一个迷信的(superstitious)家伙。他相信每一个字符串(string)里都有一个幸运字符。我们可以通过以下方法找到这个字符。例如,在字符串abbccc中,c 出现的次数最多,所以这个幸运字符就是 c 啦!(>_<)  (钟Sir的想法好简单啊…)\nInput\n第一行是测试数据的组数n,接下来的每组测试数据占一行,每行数据不超过1000个字符且非空。\n字符串里只含小写字母。\nOutput\n每组数据对应输出一行,包括出现次数最多的字符和该字符出现的次数,中间是一个空格。如果有多个字符出现的次数相同且最多,那么输出ASCII码最小的那一个字符。\nSample Input\n2\nabbccc\nadfadffasdf\nSample Output\nc 3\nf 4", + "difficulty": "简单", + "answer_id": 173122, + "answer_content": "\n\n```\n #include \n#include\"stdio.h\"\nint main(void)\n{\n\tint n,i, z[26], max, xia;\n\tchar c[1050], ch;\n\n\tscanf(\"%d\",&n);\n\twhile(n>0)\n\t{\n\t\tn--;\n\t\tscanf(\"%s\", c);\n\n\t\tfor(i=0; i<26; i++)\n\t\t\tz[i]=0;\n\t\txia=strlen(c);\n\n\t\tfor(i=0; imax){ \n\t\t\tmax=z[i];\n\t\t\txia=i;\n\t\t}\n\n\t\tch='a'+xia;\n\t\tprintf(\"%c %d\\n\", ch, max);\n\t}\n\n\treturn 0;\n}\n```\n\n", + "tag_name": "c语言", + "cpp": " #include \n#include\"stdio.h\"\nint main(void)\n{\n\tint n,i, z[26], max, xia;\n\tchar c[1050], ch;\n\tscanf(\"%d\",&n);\n\twhile(n>0)\n\t{\n\t\tn--;\n\t\tscanf(\"%s\", c);\n\t\tfor(i=0; i<26; i++)\n\t\t\tz[i]=0;\n\t\txia=strlen(c);\n\t\tfor(i=0; imax){ \n\t\t\tmax=z[i];\n\t\t\txia=i;\n\t\t}\n\t\tch='a'+xia;\n\t\tprintf(\"%c %d\\n\", ch, max);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469966", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/132.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/133.json b/data_backup/cpp_code_json/133.json new file mode 100644 index 000000000..504ca647a --- /dev/null +++ b/data_backup/cpp_code_json/133.json @@ -0,0 +1,18 @@ +{ + "question_id": 1093013, + "question_title": "偶数 or 奇数", + "question_content": "偶数 or 奇数\n时间限制: 1 Sec 内存限制: 128 MB\n题目描述\n编程班老师搞了一个有 N (1 <= N <= 100) 个正整数 I (1 <= I <= 10^60) 的表,叫 同学们去统计每个数里面数字(0,1,2,3,4,5,6,7,8,9)(注 0 为偶数)的奇偶数 字个数。写一个程序读入 N 个整数,统计每个整数的数字奇偶个数。\n输入\n第 1 行: 一个单独的整数: N \n第 2 到第 N+1 行: 每行一个长长(小于等于 60 位)的整数,需要统计数字奇偶个数。\n输出\n 1..N 行: 第 j 行根据第 j 个整数输出奇数个数与偶数个数。\n样例输入\n2\n1024\n5931\n样例输出\n1 3\n4 0", + "difficulty": "中等", + "answer_id": 1301954, + "answer_content": "代码本身没有什么问题\n关键是10^60\n因此long long可能也不够,应该用字符串。\n\n\n```\n#include\n#include\nusing namespace std;\nstring a[105];\nint b[105],c[105];\nint qiujishu(string x){\n int jishu=0;\n for(int i = 0; x.c_str()[i]; i++){\n if ((x.c_str()[i] - '0') % 2 == 1) jishu++;\n }\n return jishu;\n}\nint qiuoushu(string x){\n int oushu=0;\n for(int i = 0; x.c_str()[i]; i++){\n if ((x.c_str()[i] - '0') % 2 == 0) oushu++;\n }\n return oushu;\n}\nint main()\n{\n int n;\n cin>>n;\n for(int i=1;i<=n;i++){\n cin>>a[i];\n b[i]=qiujishu(a[i]);\n c[i]=qiuoushu(a[i]);\n }\n for(int i=1;i<=n;i++){\n cout<\n#include\nusing namespace std;\nstring a[105];\nint b[105],c[105];\nint qiujishu(string x){\n\tint jishu=0;\n\tfor(int i = 0; x.c_str()[i]; i++){\n\t\tif ((x.c_str()[i] - '0') % 2 == 1) jishu++;\n\t}\n\treturn jishu;\n}\nint qiuoushu(string x){\n\tint oushu=0;\n\tfor(int i = 0; x.c_str()[i]; i++){\n\t\tif ((x.c_str()[i] - '0') % 2 == 0) oushu++;\n\t}\n\treturn oushu;\n}\nint main()\n{\n\tint n;\n\tcin>>n;\n\tfor(int i=1;i<=n;i++){\n\t\tcin>>a[i];\n\t\tb[i]=qiujishu(a[i]);\n\t\tc[i]=qiuoushu(a[i]);\n\t}\n\tfor(int i=1;i<=n;i++){\n\t\tcout<\n#include\n#include\n#include\n#include\nusing namespace std;\nint main() {\n\tint n;\n\tcin>>n;\n\tvector a(n,\"\"),b(n,\"\");\n\tint m=(n+1)/2;\n\tint p=0;\n\tfor(int i=m-1;i>=0;i--){\n\t\tfor(int j=0;j<=i;j++)\n\t\t\ta[i].push_back('A'+j+p);\n\t\tb[i]=a[i];\n\t\treverse(b[i].begin(),b[i].end());\n\t\tfor(int j=i+1;j=m;i--){\n\t\ta[i]=a[p];\n\t\tb[i]=b[p++];\n\t}\n\tfor(int i=0;i\n#include\n#include\n#include\n#include\nusing namespace std;\nint main() {\n\tint n;\n\tcin>>n;\n\tvector a(n,\"\"),b(n,\"\");\n\tint m=(n+1)/2;\n\tint p=0;\n\tfor(int i=m-1;i>=0;i--){\n\t\tfor(int j=0;j<=i;j++)\n\t\t\ta[i].push_back('A'+j+p);\n\t\tb[i]=a[i];\n\t\treverse(b[i].begin(),b[i].end());\n\t\tfor(int j=i+1;j=m;i--){\n\t\ta[i]=a[p];\n\t\tb[i]=b[p++];\n\t}\n\tfor(int i=0;i\n#include\nint main()\n{\n int m,n;\n scanf(\"%d%d\",&n,&m);\n int i,j;\n for(i=0;i\n#include\nint main()\n{\n\tint m,n;\n\tscanf(\"%d%d\",&n,&m);\n\tint i,j;\n\tfor(i=0;i计算1!-2!+3!-4!+5!-6!+7!-8!+9!-10!,并输出计算结果

", + "difficulty": "简单", + "answer_id": 53397520, + "answer_content": "
\n#include "stdio.h"\n\ndouble fun(int n)//用double提高精度和计数位数。\n\n{\n\n    double sum=1.0;\n\n    int i;\n\n    for(i=1;i<=n;i++)\n\n           sum*=i;\n\n     return sum;\n\n}\n\n \n\nint main()\n\n{\n\n       int i,mark=1;\n\n       double sum=0,item=0;\n\n       for(i=1;i<=10;i++)\n\n       {\n\n            item=mark*fun(i);\n\n            sum+=item;\n\n            mark=-mark;\n\n       }\n\n       printf("1!-2!+3!-4!+5!-6!+7!-8!+9!-10!=%.0lf\\n",sum);\n\n\n\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \"stdio.h\"\ndouble fun(int n)\n{\n\tdouble sum=1.0;\n\tint i;\n\tfor(i=1;i<=n;i++)\n\t\tsum*=i;\n\treturn sum;\n}\nint main()\n{\n\tint i,mark=1;\n\tdouble sum=0,item=0;\n\tfor(i=1;i<=10;i++)\n\t{\n\t\titem=mark*fun(i);\n\t\tsum+=item;\n\t\tmark=-mark;\n\t}\n\tprintf(\"1!-2!+3!-4!+5!-6!+7!-8!+9!-10!=%.0lf\\n\",sum);\n}", + "topic_link": "https://bbs.csdn.net/topics/600469867", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/136.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/137.json b/data_backup/cpp_code_json/137.json new file mode 100644 index 000000000..091ee4718 --- /dev/null +++ b/data_backup/cpp_code_json/137.json @@ -0,0 +1,18 @@ +{ + "question_id": 7443725, + "question_title": "输出最长的递增数字字符串", + "question_content": "

如何在一亿位整数组成的字符串中找到最长的递增数字字符串?

", + "difficulty": "中等", + "answer_id": 53421026, + "answer_content": "

1亿个字符串占用的缓存超出了编译器的默认缓存,所以我代码中定义了一个宏来表示字符串的最大长度,如果你需要扩展到1亿,需要修改编译器的默认缓存大小,然后把宏定义的值调大即可。代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n#include <string.h>\n#define MAX_SIZE 100000\nint main()\n{\n\tchar buf[MAX_SIZE] = {0};\n\tint i = 0,len = 0,index = 0;\n\tchar maxbuf[12] = {0}; //最大的可能是0-9,最多10个字符,12个空间足够用\n\tchar maxbuf2[12] = {0};\n\tint maxlen = 0;\n\tgets(buf); //实际字符串由外部输入,或者从文件读取,这个根据实际情况修改吧\n\tlen = strlen(buf); //获取实际长度\n\n\tmaxbuf2[0] = buf[0];\n\ti = 1;\n\tindex = 1;\n\twhile(i < len)\n\t{\n\t\tif (buf[i] > buf[i-1])\n\t\t{\n\t\t\tmaxbuf2[index] = buf[i];\n\t\t\tindex++;\n\t\t}else\n\t\t{\n\t\t\tif (index > maxlen)\n\t\t\t{\n\t\t\t\tmaxlen = index;\n\t\t\t\tstrcpy(maxbuf,maxbuf2);\n\t\t\t\tmaxbuf[index] = '\\0';\n\t\t\t\t\n\t\t\t\tmaxbuf2[0] = buf[i];\n\t\t\t\tindex = 1;\n\t\t\t}else\n\t\t\t{\n\t\t\t\tmaxbuf2[0] = buf[i];\n\t\t\t\tindex = 1;\n\t\t\t}\n\t\t}\n\t\ti++;\n\t}\n\t//处理最后一个串\n\tif (index > maxlen)\n\t{\n\t\tmaxlen = index;\n\t\tstrcpy(maxbuf,maxbuf2);\n\t\tmaxbuf[index] = '\\0';\n\t}\n\tprintf("最大串长度:%d,字符串:%s\\n",maxlen,maxbuf);\n\treturn 0;\n}\n
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \n#define MAX_SIZE 100000\nint main()\n{\n\tchar buf[MAX_SIZE] = {0};\n\tint i = 0,len = 0,index = 0;\n\tchar maxbuf[12] = {0}; \n\tchar maxbuf2[12] = {0};\n\tint maxlen = 0;\n\tgets(buf); \n\tlen = strlen(buf); \n\tmaxbuf2[0] = buf[0];\n\ti = 1;\n\tindex = 1;\n\twhile(i < len)\n\t{\n\t\tif (buf[i] > buf[i-1])\n\t\t{\n\t\t\tmaxbuf2[index] = buf[i];\n\t\t\tindex++;\n\t\t}else\n\t\t{\n\t\t\tif (index > maxlen)\n\t\t\t{\n\t\t\t\tmaxlen = index;\n\t\t\t\tstrcpy(maxbuf,maxbuf2);\n\t\t\t\tmaxbuf[index] = '\\0';\n\t\t\t\tmaxbuf2[0] = buf[i];\n\t\t\t\tindex = 1;\n\t\t\t}else\n\t\t\t{\n\t\t\t\tmaxbuf2[0] = buf[i];\n\t\t\t\tindex = 1;\n\t\t\t}\n\t\t}\n\t\ti++;\n\t}\n\tif (index > maxlen)\n\t{\n\t\tmaxlen = index;\n\t\tstrcpy(maxbuf,maxbuf2);\n\t\tmaxbuf[index] = '\\0';\n\t}\n\tprintf(\"最大串长度:%d,字符串:%s\\n\",maxlen,maxbuf);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469968", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/137.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/138.json b/data_backup/cpp_code_json/138.json new file mode 100644 index 000000000..31de8b013 --- /dev/null +++ b/data_backup/cpp_code_json/138.json @@ -0,0 +1,18 @@ +{ + "question_id": 985858, + "question_title": "移动数组中的元素", + "question_content": "题目描述\n将一维数组中的元素循环左移 k 个位置\n输入描述\n第 1 行是一维数组元素的个数 n (数组大小)\n第 2 行是一个整数 k , 表示移动的位置\n下面 n 行为数组的元素个数\n输出描述\n输出 n 行,表示移动后的数字", + "difficulty": "简单", + "answer_id": 1149184, + "answer_content": "\n```\n#include\n#define N 10000\nint main()\n{\n int k,a[N],b[N],n,t,w,i;\n scanf(\"%d\",&n);\n scanf(\"%d\",&k);\n for(i=0;i\n#define N 10000\nint main()\n{\n\tint k,a[N],b[N],n,t,w,i;\n\tscanf(\"%d\",&n);\n\tscanf(\"%d\",&k);\n\tfor(i=0;i有n人(编号分别为1到n号)围成一圈,从第s人开始报数,报到第m的人出列,然后从出列的下一人重新开始报数,报到第m的人又出列,……,如此重复直到n-1全部出列,只剩最后一个人为止。求剩下的最后一人是谁?\n输入\n一行,三个整数n,m,s,(0<=n,m,s<=1000)意义如上。\n输出\n一行,一个正整数,表示最后剩下的人的编号。\n输入样例

\n
\n8 3 1
\n

输出样例

\n
\n7\n
\n

要求从第s个数开始,数m个出列,第s个不出列

", + "difficulty": "困难", + "answer_id": 53358508, + "answer_content": "
\n#include <iostream>\n \nvoid JosePhus(int n, int m, int start) {\n    int i, *arr = new int[n]; // 动态分配数组\n    int count = 1;; // 保存当前已站出来的人数\n    for(i = 0;i < n; i++) // 初始化,把各位置号存入数组中\n        arr[i] = i + 1;\n    int sum = n;\n    //输出参考    printf("出列顺序为:");\n    while(count < n) { // 出列顺序\n        start--; // 因为数组下标从0开始,所以要减1\n        int index = (start+m-1) % sum;//记录第count次出列的下标 \n    //输出参考  std::cout << arr[index] << " "; // 输出当前要站出来的人的位置号\n        for(i = index; i < sum-1; i++)//出列相当于人数少了一个,循环上限为sum-1\n            arr[i] = arr[i+1]; // 把位置号前移\n        start = index + 1;//第count+1次开始位置为上次出列下标位置+1\n        sum--;//总人数减一 \n        count++;//出列人数+1 \n    }\n    std::cout<< arr[0] <<"\\n";//最后剩下的第一个元素为最后留下的人\n}\n \nint main(int argc, const char * argv[]) {\n    int n, m, start; // n:人数  m:数到多少出列  start:开始位置\n \n    std::cout << "请输入n,m,start:\\n";\n    while(std::cin >> n >> m >> start) {\n        JosePhus(n, m, start); // 调用解决约瑟夫问题的函数\n        std::cout << "请输入n,m,start:\\n";\n    }\n    return 0;\n}
\n\n

 

", + "tag_name": "c++", + "cpp": "#include \nvoid JosePhus(int n, int m, int start) {\n    int i, *arr = new int[n]; \n    int count = 1;; \n    for(i = 0;i < n; i++) \n        arr[i] = i + 1;\n    int sum = n;\n    while(count < n) { \n        start--; \n        int index = (start+m-1) % sum;\n        for(i = index; i < sum-1; i++)\n            arr[i] = arr[i+1]; \n        start = index + 1;\n        sum--;\n        count++;\n    }\n    std::cout<< arr[0] <<\"\\n\";\n}\nint main(int argc, const char * argv[]) {\n    int n, m, start; \n    std::cout << \"请输入n,m,start:\\n\";\n    while(std::cin >> n >> m >> start) {\n        JosePhus(n, m, start); \n        std::cout << \"请输入n,m,start:\\n\";\n    }\n    return 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469969", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/139.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/14.json b/data_backup/cpp_code_json/14.json new file mode 100644 index 000000000..63232ea1f --- /dev/null +++ b/data_backup/cpp_code_json/14.json @@ -0,0 +1,18 @@ +{ + "question_id": 7435119, + "question_title": "指针排序问题", + "question_content": "

输入10个数,按绝对值从大到小排序输出。\n输入形式:输入10个float实数\n输出形式:保留小数点后两位有效数字;输出从大到小排列\n

", + "difficulty": "困难", + "answer_id": 53405662, + "answer_content": "
\n#include <math.h>\n#include <stdio.h>\nvoid paixu(float *p,int n)\n{\n\tint i,j;\n\tfor (i = 0; i<n-1; i++) \n\t{ //控制n-1趟冒泡\n\t\tfor (j = 0; j<n - 1 - i; j++)\n\t\t{\n\t\t\tif (fabs(p[j])<fabs(p[j + 1])) \n\t\t\t{ //比较相邻的两个元素\n\t\t\t\tfloat tmp; //临时变量\n\t\t\t\ttmp = p[j]; //交换\n\t\t\t\tp[j] = p[j + 1];\n\t\t\t\tp[j + 1] = tmp;\n\t\t\t}\n\t\t}\n\t}\n}\n\nint main()\n{\n\tfloat f[10];\n\tint i;\n\tfor(i=0;i<10;i++)\n\t\tscanf("%f",&f[i]);\n\tpaixu(f,10);\n\tfor(i=0;i<10;i++)\n\t\tprintf("%.2f ",f[i]);\n\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nvoid paixu(float *p,int n)\n{\n\tint i,j;\n\tfor (i = 0; i\n#include \n#include \n#include \nusing namespace std;\n\n//比较函数,用于排序\nbool compare(string a,string b) {\n //长度不一样的时候采用长度来排序\n if (a.length() != b.length()) {\n return a.length() < b.length();\n }\n //长度一样的时候采用ASCII值排序\n return a < b;\n}\n\nint main()\n{\n \n vectorlist;\n \n string inputString;\n \n while (cin>>inputString) {\n \n //结束标志,测试方便,可以注释掉\n if (inputString == \"0\") {\n break;\n }\n //加入到vector\n list.push_back(inputString);\n }\n //排序,系统方法\n sort(list.begin(),list.end(),compare);\n //依次输出\n for (int i=0; i\n#include \n#include \n#include \nusing namespace std;\nbool compare(string a,string b) {\n\tif (a.length() != b.length()) {\n\t return a.length() < b.length();\n\t}\n\treturn a < b;\n}\nint main()\n{\n\tvectorlist;\n\tstring inputString;\n\twhile (cin>>inputString) {\n\t\tif (inputString == \"0\") {\n\t\t\tbreak;\n\t\t}\n\t\tlist.push_back(inputString);\n\t}\n\tsort(list.begin(),list.end(),compare);\n\tfor (int i=0; i利用公式x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b - sqrt(b*b-4*a*c))/(2*a)求一元二次方程ax2 + bx + c =0 的根,其中a不等于0。\n输入一行,包含三个浮点数a, b, c(它们之间以一个空格分开),分别表示方程ax2 + bx + c =0 的系数。输出一行,表示方程的解。\n若两个实根相等,则输出形式为:x1=x2=...。\n若两个实根不等,则输出形式为:x1=...;x2 = ...,其中x1若是两个虚根,则输出:x1=实部+虚部i; x2=实部-虚部i,其中x1,x2满足以下两个条件中的一个:\n1. x1的实部大于x2的实部\n2. x1的实部等于x2的实部且x1的虚部大于等于x2的虚部\n所有实数部分要求精确到小数点后5位,数字、符号之间没有空格。\n样例输入:1.0 2.0 8.0\n样例输出:x1=-1.00000+2.64575i;x2=-1.00000-2.64575i", + "difficulty": "困难", + "answer_id": 198570, + "answer_content": "\n\n```\n #include \n#include\n#include \n#include \nusing namespace std;\nstatic const double e = 1e-12;\nbool operator == (complex c1, complex c2) { return abs(c1-c2) < e;}\nint main()\n{\n complex a,b,c;\n complex x1,x2;\n cin >> a >> b >> c;\n x1 = (-b + sqrt(b*b-a*c*4.0))/(a*2.0);\n x2 = (-b - sqrt(b*b-a*c*4.0))/(a*2.0);\n cout << setiosflags(ios::fixed);\n cout.precision(6);\n if ( abs(x1.imag()) < e ) // real\n {\n if (x1 == x2) {\n cout << \"x1=x2=\" << x1.real();\n } else {\n cout << \"x1=\" << x1.real() <<\";x2=\" << x1.real();\n }\n }\n else {\n cout << \"x1=\" << x1.real()<<\"+\"<\n#include\n#include \n#include \nusing namespace std;\nstatic const double e = 1e-12;\nbool operator == (complex c1, complex c2) { return abs(c1-c2) < e;}\nint main()\n{\n\tcomplex a,b,c;\n\tcomplex x1,x2;\n\tcin >> a >> b >> c;\n\tx1 = (-b + sqrt(b*b-a*c*4.0))/(a*2.0);\n\tx2 = (-b - sqrt(b*b-a*c*4.0))/(a*2.0);\n\tcout << setiosflags(ios::fixed);\n\tcout.precision(6);\n\tif ( abs(x1.imag()) < e ) \n\t{\n\t\tif (x1 == x2) {\n\t\t\tcout << \"x1=x2=\" << x1.real();\n\t\t} else {\n\t\t\tcout << \"x1=\" << x1.real() <<\";x2=\" << x1.real();\n\t\t}\n\t}\n\telse {\n\t\tcout << \"x1=\" << x1.real()<<\"+\"<\nusing namespace std;\n#include \nvoid reverse(char *a,int start, int end)\n{\n int i ,j,temp;\n for(i = start,j = end; i < j; i++,j--)\n {\n temp = a[i];\n a[i] = a[j];\n a[j] = temp;\n } \n}\nvoid turnleft(char *a,int i,int n)\n{\n int left = i % n;\n if(left == 0)\n return ;\n reverse(a,0,left-1);\n reverse(a,left,n-1);\n reverse(a,0,n-1);\n return ;\n}\nint main()\n{\n char a[1024];\n int i; \n\tcin>>i;\n\tcin>>a;\n int n = strlen(a);\n turnleft(a,i,n);\n\tcout<\n#include \nusing namespace std;\nvoid reverse(char *a,int start, int end)\n{\n\tint i ,j,temp;\n\tfor(i = start,j = end; i < j; i++,j--)\n\t{\n\t\ttemp = a[i];\n\t\ta[i] = a[j];\n\t\ta[j] = temp;\n\t} \n}\nvoid turnleft(char *a,int i,int n)\n{\n\tint left = i % n;\n\tif(left == 0)\n\t\treturn ;\n\treverse(a,0,left-1);\n\treverse(a,left,n-1);\n\treverse(a,0,n-1);\n\treturn ;\n}\nint main()\n{\n\tchar a[1024];\n\tint i;\t\n\tcin>>i;\n\tcin>>a;\n\tint n = strlen(a);\n\tturnleft(a,i,n);\n\tcout< 0)\n {\n if (s[x - 1] == 'O')temp++;\n else break; \n x--;\n }\n score += temp;\n }\n }\n }\n printf(\"%d\\n\", score);\n\t\tsystem(\"pause\");\n return 0;\n}", + "tag_name": "c语言", + "cpp": "#include\"stdlib.h\"\n#include\"string.h\"\n#include\"stdio.h\"\nint main()\n{\n\tchar s[85];\n\tint score = 0,x;\n\tscanf(\"%s\",&s);\n\tfor (int i = 0;s[i];i++)\n\t{\n\t\tif (s[i] == 'X')\n\t\tscore += 0;\n\t\tif (s[i] == 'O')\n\t\t{\n\t\t\tint temp = 1;\n\t\t\tif (i == 0)score += 1;\n\t\t\telse\n\t\t\t{\n\t\t\t\tx=i;\n\t\t\t\twhile (x > 0)\n\t\t\t\t{\n\t\t\t\t\tif (s[x - 1] == 'O')temp++;\n\t\t\t\t\telse break; \n\t\t\t\t\tx--;\n\t\t\t\t}\n\t\t\t\tscore += temp;\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"%d\\n\", score);\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469970", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/143.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/144.json b/data_backup/cpp_code_json/144.json new file mode 100644 index 000000000..a0e5b72ed --- /dev/null +++ b/data_backup/cpp_code_json/144.json @@ -0,0 +1,17 @@ +{ + "question_id": 1081343, + "question_title": "编写计算组合数的程序?", + "question_content": "1.编写计算组合数的程序。\n\n问题分析:\n\n(1)组合数的计算公式为:\n\n \n\n(2)此公式中用到3次阶乘的计算,所以可以编写一个求阶层函数fact(x)。\n\n(3)函数fact(x)的功能为计算整数x的阶层。\n\n要求:上传运行结果截图时,输入n的值为10,m的值为4。程序运行结果参考下图:![图片说明](https://img-ask.csdn.net/upload/202006/07/1591491052_938571.png)", + "difficulty": "简单", + "answer_id": 1287002, + "answer_content": "\n```\n#include \nint fact(int n)\n{\nint r = 1;\nfor (int i = 1; i <= n; i++) r *= i;\nreturn r;\n}\nint main()\n{\nint m, n;\nscanf(\"%d%d\", &m, &n);\nint c = fact(n) / (fact(m) * fact(n - m));\nprintf(\"c=%d\", c);\nreturn 0;\n}\n```\n# 问题解决的话,请点下采纳", + "tag_name": "c语言", + "cpp": "#include \nint fact(int n)\n{\nint r = 1;\nfor (int i = 1; i <= n; i++) r *= i;\nreturn r;\n}\nint main()\n{\nint m, n;\nscanf(\"%d%d\", &m, &n);\nint c = fact(n) / (fact(m) * fact(n - m));\nprintf(\"c=%d\", c);\nreturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469869", + "status": 0, + "keywords": "算法中阶,摊还分析,聚合分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/144.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/15.json b/data_backup/cpp_code_json/15.json new file mode 100644 index 000000000..cd3282ad6 --- /dev/null +++ b/data_backup/cpp_code_json/15.json @@ -0,0 +1,17 @@ +{ + "question_id": 227460, + "question_title": "实现从键盘输入一行字符串,将该字符串中所有的apple换成orange.如:I have an apple.Do you like apple? 变为I have an orange.Do you like orange?", + "question_content": "实现从键盘输入一行字符串,将该字符串中所有的apple换成orange.如:I have an apple.Do you like apple? 变为I have an orange.Do you like orange?", + "difficulty": "中等", + "answer_id": 191734, + "answer_content": "\n\n```\n #include\n#include\nint main()\n{\n\tchar s[]=\"I have an apple Do you like apple\";\n\tchar s1[]=\"apple\";\n\tchar s2[]=\"orange\";\n\tint a[10],i,j,k,n=0,h,m=0;\n\tfor(i=0;s[i]!='\\0';i++)\n\t\tfor(j=i,k=0;s1[k]==s[j];k++,j++)\n\t\t\tif(s1[k+1]=='\\0')\n\t\t\t{\n\t\t\t\tm++;\n\t\t\t\ta[n++]=j-k;\n\t\t\t\tbreak;\n\t\t\t}\n\tfor(n=0;n\n#include\nint main()\n{\n\tchar s[]=\"I have an apple Do you like apple\";\n\tchar s1[]=\"apple\";\n\tchar s2[]=\"orange\";\n\tint a[10],i,j,k,n=0,h,m=0;\n\tfor(i=0;s[i]!='\\0';i++)\n\t\tfor(j=i,k=0;s1[k]==s[j];k++,j++)\n\t\t\tif(s1[k+1]=='\\0')\n\t\t\t{\n\t\t\t\tm++;\n\t\t\t\ta[n++]=j-k;\n\t\t\t\tbreak;\n\t\t\t}\n\tfor(n=0;n=1,∑ki<=3×105,1<=x(i,j)<=105,1<=ti-1\n#include\n#include\n#include\n#include\n#include\nusing namespace std;\nint a[100100];\nint people[500100];\nstruct node{\n int country;\n int time;\n};\nqueueq;\nint main(){\n int n,sum=0;\n scanf(\"%d\",&n);\n for(int i=1;i<=n;i++){\n int t,p;\n scanf(\"%d%d\",&t,&p);\n node temp;\n temp.time=t;\n for(int i=1;i<=p;i++){\n int cty;\n scanf(\"%d\",&cty);\n temp.country=cty;\n q.push(temp);\n if(!people[cty]) sum++;\n people[cty]++;\n }\n while(1){\n node old;\n old=q.front();\n if(temp.time-86400>=old.time)\n {\n int tc=old.country;\n people[tc]--;\n if(!people[tc]) sum--;\n q.pop();\n }\n else break; \n }\n cout<\n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint a[100100];\nint people[500100];\nstruct node{\n\tint country;\n\tint time;\n};\nqueueq;\nint main(){\n\tint n,sum=0;\n\tscanf(\"%d\",&n);\n\tfor(int i=1;i<=n;i++){\n\t\tint t,p;\n\t\tscanf(\"%d%d\",&t,&p);\n\t\tnode temp;\n\t\ttemp.time=t;\n\t\tfor(int i=1;i<=p;i++){\n\t\t\tint cty;\n\t\t\tscanf(\"%d\",&cty);\n\t\t\ttemp.country=cty;\n\t\t\tq.push(temp);\n\t\t\tif(!people[cty]) sum++;\n\t\t\tpeople[cty]++;\n\t\t}\n\t\twhile(1){\n\t\t\tnode old;\n\t\t\told=q.front();\n\t\t\tif(temp.time-86400>=old.time)\n\t\t\t{\n\t\t\t\tint tc=old.country;\n\t\t\t\tpeople[tc]--;\n\t\t\t\tif(!people[tc]) sum--;\n\t\t\t\tq.pop();\n\t\t\t}\n\t\t\telse break; \n\t\t}\n\t\tcout<

从键盘输入m(2<=m<=6)行n(2<=n<=6)列整型数据,编程找出其中的最大值及其所在位置的行列下标值并输出。\n输入格式:\n在第一行输入数据的行数m和列数n的值,从第二行开始以二维数组的形式依次输入m行n列整型数据。\n输出格式:\n依次输出最大值及其所在位置的行列下标值,中间以逗号,分隔,最后换行。\n输入样例:

\n
\n3 4\n1 2 3 4\n8 9 7 6\n5 6 7 0
\n

输出样例:

\n
\n9,1,1
", + "difficulty": "中等", + "answer_id": 53428211, + "answer_content": "

代码如下:

\n\n
\n#include <stdio.h>\nint main ()\n{\n\tint a[6][6];\n\tint m,n;\n\tint i,j;\n\tint max;\n\tint indexx=0,indexy=0;\n\tscanf("%d %d",&m,&n);\n\tfor (i = 0;i<m;i++)\n\t{\n\t\tfor (j = 0;j<n;j++)\n\t\t{\n\t\t\tscanf("%d",&a[i][j]);\n\t\t\tif(i == 0 && j==0)\n\t\t\t{\n\t\t\t\tmax = a[i][j];\n\t\t\t\tindexx = 0;\n\t\t\t\tindexy = 0;\n\t\t\t}else\n\t\t\t{\n\t\t\t\tif (a[i][j] > max)\n\t\t\t\t{\n\t\t\t\t\tmax = a[i][j];\n\t\t\t\t\tindexx = i;\n\t\t\t\t\tindexy = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\tprintf("%d,%d,%d\\n",max,indexx,indexy);\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint main ()\n{\n\tint a[6][6];\n\tint m,n;\n\tint i,j;\n\tint max;\n\tint indexx=0,indexy=0;\n\tscanf(\"%d %d\",&m,&n);\n\tfor (i = 0;i max)\n\t\t\t\t{\n\t\t\t\t\tmax = a[i][j];\n\t\t\t\t\tindexx = i;\n\t\t\t\t\tindexy = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tprintf(\"%d,%d,%d\\n\",max,indexx,indexy);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470252", + "status": 1, + "keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/17.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/18.json b/data_backup/cpp_code_json/18.json new file mode 100644 index 000000000..52d6227a3 --- /dev/null +++ b/data_backup/cpp_code_json/18.json @@ -0,0 +1,18 @@ +{ + "question_id": 1064299, + "question_title": "请问如何实现这个代码的多组输入输出?", + "question_content": "

给定 2 个正整数 a, b ,a 和 b 最多可能有 40 位,求出 a + b 的和。\n输入描述\n两个正整数 a, b,a 和 b 最多可能有 40 位。一行表示一个数。\n输出描述\na + b 的和。

样例输入

111111111111111111111111111111111111111\n222222222222222222222222222222222222222\n

样例输出

333333333333333333333333333333333333333\n
", + "difficulty": "简单", + "answer_id": 1262493, + "answer_content": "\n```\n#include\n#include\nusing namespace std;\nint main(){\n\twhile (1)\n\t{\n\t\tchar s1[200],s2[200];\n\t\tint a[200]={0},b[200]={0},l1,l2,c,k,i;\n\t\tgets(s1);\n\t\tl1=strlen(s1);\n\t\tif (l1 == 0) break;\n\t\tgets(s2);\n\t\tl2=strlen(s2);\n\t\tif(l1=0;i--){\n\t\t\ta[i]+=b[i];\n\t\t\tif(a[i]>=10){\n\t\t\t\ta[i]=10;\n\t\t\t\ta[i-1]++;\n\t\t\t}\n\t\t}\n\t\tif(a[0]!=0){\n\t\t\tfor(i=0;i<=c;i++)\n\t\t\t\tcout<\n#include \nusing namespace std;\nint main(){\n\twhile (1)\n\t{\n\t\tchar s1[200],s2[200];\n\t\tint a[200]={0},b[200]={0},l1,l2,c,k,i;\n\t\tgets(s1);\n\t\tl1=strlen(s1);\n\t\tif (l1 == 0) break;\n\t\tgets(s2);\n\t\tl2=strlen(s2);\n\t\tif(l1=0;i--){\n\t\t\ta[i]+=b[i];\n\t\t\tif(a[i]>=10){\n\t\t\t\ta[i]=10;\n\t\t\t\ta[i-1]++;\n\t\t\t}\n\t\t}\n\t\tif(a[0]!=0){\n\t\t\tfor(i=0;i<=c;i++)\n\t\t\t\tcout<简单数列5
\n 已知一数列:1,3,3,5,5,5,7,7,7,7,9,9,9,9,9,11,11,11,11,11,11,11.....请根据规律求出第n项的值。例如:n=4 项时,其值为5,n=11时,其值为9.\n输入格式 一个自然数n,(0<n<1000)
\n
\n输出格式 一个整数,即第n项的值。
\n样例输入:4
\n样例输出 :5

\n", + "difficulty": "简单", + "answer_id": 53441264, + "answer_content": "
\n#include <iostream>\nusing namespace std;\n\nint main(){\n int a,b;\n cin>>a;\n \n int n=1,count=1,num=1;\n \n for(int i=0;i<a;i++)\n {\n     if(count > n)\n     {\n         num+=2;\n         n++;\n         count=1;\n         i--;\n     }\n     else\n     {\n        cout << num << ",";    //输出整个数列\n        count++;\n     }\n }\n cout << endl;\n \n \n cout << num;\n \n return 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nusing namespace std;\nint main(){\n\tint a,b;\n\tcin>>a;\n\tint n=1,count=1,num=1;\n\tfor(int i=0;i n)\n\t\t{\n\t\t\tnum+=2;\n\t\t\tn++;\n\t\t\tcount=1;\n\t\t\ti--;\n\t\t}\n\t\telse\n\t\t{\n\t\tcout << num << \",\";\t\n\t\tcount++;\n\t\t}\n\t}\n\tcout << endl;\n\tcout << num;\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470254", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/19.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/2.json b/data_backup/cpp_code_json/2.json new file mode 100644 index 000000000..a75b302aa --- /dev/null +++ b/data_backup/cpp_code_json/2.json @@ -0,0 +1,18 @@ +{ + "question_id": 7398746, + "question_title": "可怕的流感 ", + "question_content": "

Ø 问题描述:已知一只家禽得了流感,流感的传播时间为 24 小时,在这 24 小时内最多能将流感传给其它 M 只家禽,农场主需要购买紧急药品,假设发现时已经过了 N 天,那么农场主需要至少买多少包药呢?(一包药为一只家禽用量)

Ø 输入:一行,两个整数,第一个表示流感传染家禽的数量 M,第二个表示发现时已过的天数。

Ø 输出:一行,一个整数,表示需要药的包数。

Ø 样例输入:

10 2

Ø 样例输出:

121

", + "difficulty": "困难", + "answer_id": 53345307, + "answer_content": "
\n#include<iostream>\nusing namespace std;\nint total(int x);              //定义函数\nint m;                         //m为感染数\nint main() {\n\tint  x;                     //x为发现天数\n\tcin >> m >> x;\n\tint to = total(x);           //to为结果\n\tcout << to;\n\treturn 0;\n}\nint total(int x) {\n\tif (x > 0)\n\t{\n\t\treturn (m + 1) * total(x - 1);\n\t}\n\telse return 1;\n}\n
\n\n

 \"\"

", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint total(int x);\t\t\t \nint m;\t\t\t\t\t\t \nint main() {\n\tint x;\t\t\t\t\t \n\tcin >> m >> x;\n\tint to = total(x);\t\t \n\tcout << to;\n\treturn 0;\n}\nint total(int x) {\n\tif (x > 0)\n\t{\n\t\treturn (m + 1) * total(x - 1);\n\t}\n\telse return 1;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469842", + "status": 1, + "keywords": "算法初阶,快速排序,快速排序分析,期望运行时间,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/2.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/20.json b/data_backup/cpp_code_json/20.json new file mode 100644 index 000000000..c5bd611e1 --- /dev/null +++ b/data_backup/cpp_code_json/20.json @@ -0,0 +1,18 @@ +{ + "question_id": 7431172, + "question_title": "一个班有10个同学,通过键盘输入成绩,并打印输出,每行输出5个同学的成绩。并求出平均成绩,最高分、最低分并输出。", + "question_content": "

一个班有10个同学,通过键盘输入成绩,\n并打印输出,每行输出5个同学的成绩。并求出平均成绩,最高分、最低分并输出。算法分析:\n(1)定义一个数组用来存放10个成绩数据。\n(2)用循环结构实现成绩输入;\n(3)用循环结构实现成绩输出,并控制换行;\n(4)使用循环结构求平均成绩、最高分、最低分并输出。

", + "difficulty": "简单", + "answer_id": 53399158, + "answer_content": "
\n#include<stdio.h>\n\nint main(){\n    int x,i,max=0,min=0;\n    double sum=0,ave=0;\n    int a[10];\n    for(i=0;i<10;i++){\n        scanf("%d",&a[i]);\n        sum+=a[i];\n        if(max<a[i])\n            max=a[i];\n        if(min>a[i])\n            min=a[i];\n    }\n    ave=sum/10;\n    for(i=0;i<5;i++)\n        printf("%d ",a[i]);\n     printf("\\n");\n    for(i=5;i<10;i++)\n        printf("%d ",a[i]);\n    printf("平均成绩%f,最高分%d,最低分%d ",ave,max,min);\n\n}\n
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \nint main(){\n\tint x,i,max=0,min=0;\n\tdouble sum=0,ave=0;\n\tint a[10];\n\tfor(i=0;i<10;i++){\n\t\tscanf(\"%d\",&a[i]);\n\t\tif(i==0)\n\t\t\tmin = a[i];\n\t\tsum+=a[i];\n\t\tif(maxa[i])\n\t\t\tmin=a[i];\n\t}\n\tave=sum/10;\n\tfor(i=0;i<5;i++)\n\t\tprintf(\"%d \",a[i]);\n\t printf(\"\\n\");\n\tfor(i=5;i<10;i++)\n\t\tprintf(\"%d \",a[i]);\n\tprintf(\"平均成绩%f,最高分%d,最低分%d \",ave,max,min);\n}", + "topic_link": "https://bbs.csdn.net/topics/600470145", + "status": 1, + "keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/20.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/21.json b/data_backup/cpp_code_json/21.json new file mode 100644 index 000000000..d5eb9b2c0 --- /dev/null +++ b/data_backup/cpp_code_json/21.json @@ -0,0 +1,18 @@ +{ + "question_id": 7404098, + "question_title": "一个整数的序列,要求对其重新排序", + "question_content": "

一个整数的序列,要求对其重新排序。排序要求:\n1.奇数在前,偶数在后;\n2.奇数按从大到小排序;\n3.偶数按从小到大排序。
\n输入一行,包含整数个数n, n个整数值,彼此以一个空格分开。\n按照要求排序后输出一行,包含排序后的n 个整数。\n 

", + "difficulty": "简单", + "answer_id": 53352887, + "answer_content": "

用一个数组也可以的:

\n\n

#include <iostream>
\n#include<algorithm>
\nusing namespace std;

\n\n

bool cmp(int a, int b){
\n    int x = a % 2;
\n    int y = b % 2;
\n    if(x == y)
\n        if(x == 0)
\n            return a < b;
\n        else
\n            return a > b;
\n    else
\n        return x > y;
\n}

\n\n


\nint main()
\n{
\n    int n, i;
\n    cin >> n;
\n    int a[n];
\n    for(i = 0; i < n; i++)
\n        cin >> a[i];
\n    sort(a, a+n, cmp);
\n    for(i = 0; i < n; i++)
\n        cout << a[i] << " ";
\n}

", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nbool cmp(int a, int b){\n    int x = a % 2;\n    int y = b % 2;\n    if(x == y)\n        if(x == 0)\n            return a < b;\n        else\n            return a > b;\n    else\n        return x > y;\n}\nint main()\n{\n    int n, i;\n    cin >> n;\n    int a[n];\n    for(i = 0; i < n; i++)\n        cin >> a[i];\n    sort(a, a+n, cmp);\n    for(i = 0; i < n; i++)\n        cout << a[i] << \" \";\n}", + "topic_link": "https://bbs.csdn.net/topics/600470146", + "status": 1, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/21.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/22.json b/data_backup/cpp_code_json/22.json new file mode 100644 index 000000000..0736500e3 --- /dev/null +++ b/data_backup/cpp_code_json/22.json @@ -0,0 +1,18 @@ +{ + "question_id": 768078, + "question_title": "如何根据一个值,查找一个对应关系表,获得对应值呢?", + "question_content": "

如何根据一个小范围值区间,查找一个对应关系表,获得一个对应值呢\n例如电压值为2000~2026(mv),![图片说明](https://img-ask.csdn.net/upload/201907/03/1562152764_309711.png)\n其对应功率值为-52(dB),如何编程,完成建表,查表,获得结果呢?

", + "difficulty": "困难", + "answer_id": 827931, + "answer_content": "\n```\n/*17点:一一对应版本*/\n#include \n\n#define NG (0xFF)\n\n//data structure\ntypedef struct\n{\n\t\tint voltage;\n\t\tint power;\t\n}stVoltPowerTbl;\n\n//table\nconst stVoltPowerTbl myTable[] = \n{\n\t\t{-19,1083},\n\t\t{-18,1049},\n\t\t{-17,1025},\n\t\t{-16,996},\n\t\t//add your data \n};\n\nint Find(int voltage)\n{\n\t\tint Ret = NG;\n\t\tint i = 0;\n\t\t\n\t\tfor(i=0;i<((sizeof(myTable))/(sizeof(stVoltPowerTbl)));i++)\n\t\t{\n\t\t\t\tif(myTable[i].voltage == voltage)\n\t\t\t\t{\n\t\t\t\t\t\tRet = myTable[i].power;\n\t\t\t\t}\n\t\t}\n\t\treturn Ret;\n}\n\nint main()\n{\n\t\tint Ret = 0;\n\t\t\n\t\tRet = Find(-17);\n\t\t\n\t\tif(Ret != NG)\n\t\t{ \n\t\t\t\tprintf(\"power = %d \\n\",Ret);\n\t\t}\n\t\telse\n\t\t{ \n\t\t\t\tprintf(\"Error Voltage! \\n\");\n\t\t}\n\t\t\n\t\treturn 0;\n}\n```\n\n```\n/*21点:根据范围求对应值版本*/\n#include \n\n#define NG (0xFF)\n\n//data structure\ntypedef struct\n{\n\t\tint power;\t\t\n\t\tint minVoltage;\n\t\tint maxVoltage;\n}stVoltPowerTbl;\n\n//table\nconst stVoltPowerTbl myTable[] = \n{\n\t\t{-55,2080,2094},\n\t\t{-54,2060,2075},\n\t\t{-52,2000,2026},\n\t\t//add your data \n};\n\n\nint Find(int voltage)\n{\n\t\tint Ret = NG;\n\t\tint i = 0;\n\t\t\n\t\tfor(i=0;i<((sizeof(myTable))/(sizeof(stVoltPowerTbl)));i++)\n\t\t{\n\t\t\t\tif((myTable[i].minVoltage < voltage)&&(myTable[i].maxVoltage > voltage))\n\t\t\t\t{\n\t\t\t\t\t\tRet = myTable[i].power;\n\t\t\t\t}\n\t\t}\n\t\treturn Ret;\n}\n\nint main()\n{\n\t\tint Ret = 0;\n\t\t\n\t\tRet = Find(2001);\n\t\t\n\t\tif(Ret != NG)\n\t\t{ \n\t\t\t\tprintf(\"power = %d \\n\",Ret);\n\t\t}\n\t\telse\n\t\t{ \n\t\t\t\tprintf(\"Error Voltage! \\n\");\n\t\t}\n\t\t\n\t\treturn 0;\n}\n```", + "tag_name": "c语言", + "cpp": "#include \n#define NG (0xFF)\ntypedef struct\n{\n\tint voltage;\n\tint power;\t\n}stVoltPowerTbl;\nconst stVoltPowerTbl myTable[] = \n{\n\t{-19,1083},\n\t{-18,1049},\n\t{-17,1025},\n\t{-16,996},\n};\nint Find(int voltage)\n{\n\tint Ret = NG;\n\tint i = 0;\n\tfor(i=0;i<((sizeof(myTable))/(sizeof(stVoltPowerTbl)));i++)\n\t{\n\t\tif(myTable[i].voltage == voltage)\n\t\t{\n\t\t\tRet = myTable[i].power;\n\t\t}\n\t}\n\treturn Ret;\n}\nint main()\n{\n\tint Ret = 0;\n\tRet = Find(-17);\n\tif(Ret != NG)\n\t{\t\n\t\tprintf(\"power = %d \\n\",Ret);\n\t}\n\telse\n\t{\t\n\t\tprintf(\"Error Voltage! \\n\");\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470255", + "status": 0, + "keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/22.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/23.json b/data_backup/cpp_code_json/23.json new file mode 100644 index 000000000..41712eabc --- /dev/null +++ b/data_backup/cpp_code_json/23.json @@ -0,0 +1,17 @@ +{ + "question_id": 7409321, + "question_title": "如何实现凯撒密码对文本文件(.txt)的读取穷举暴力破解?", + "question_content": "

对文本文件中凯撒密码穷举破解 并把26次结果 输出为二十六个文本文件(.txt)

", + "difficulty": "中等", + "answer_id": 53360172, + "answer_content": "

 将输入数据放于"read.txt"文件中,编译运行程序即可。

\n\n
\n#include<stdio.h>\n\nint main(void){\n\tFILE *fp=NULL;\n\tchar c[200000],x;\n\tint i=0,n=0,j=0;\n\t\n\tfp=fopen("read.txt","r"); //读取txt文件数据 \n\twhile((x=fgetc(fp))!=EOF){\n\t\tc[i]=x;\n\t\ti++;\n\t}\n\tn=i;\n\tc[n]='\\0';\n\tfclose(fp);\n\t\n\tchar f[20]="write00.txt";\n\tfor(i=1;i<=26;i++){\n\t\tif(f[6]=='9'){  //将输出文件从01至26排序 \n\t\t\tf[6]='0';\n\t\t\tf[5]++;\n\t\t}\n\t\telse\n\t\t\tf[6]++;\n\t\n\t\tfor(j=0;j<n;j++){  //进行暴力破解,一次将所有字母往后移动一位 \n\t\t\tif(c[j]>='a'&&c[j]<'z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='z')\n\t\t\t\tc[j]='a';\n\t\t\tif(c[j]>='A'&&c[j]<'Z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='Z')\n\t\t\t\tc[j]='A';\n\t\t}\n\t\t\n\t\tfp=fopen(f,"w");//输出文件 \n\t\tfputs(c,fp);\n\t\tfclose(fp);\n\t}\n\treturn 0;\n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\nint main(void){\n\tFILE *fp=NULL;\n\tchar c[200000],x;\n\tint i=0,n=0,j=0;\n\tfp=fopen(\"read.txt\",\"r\"); \n\twhile((x=fgetc(fp))!=EOF){\n\t\tc[i]=x;\n\t\ti++;\n\t}\n\tn=i;\n\tc[n]='\\0';\n\tfclose(fp);\n\tchar f[20]=\"write00.txt\";\n\tfor(i=1;i<=26;i++){\n\t\tif(f[6]=='9'){ \n\t\t\tf[6]='0';\n\t\t\tf[5]++;\n\t\t}\n\t\telse\n\t\t\tf[6]++;\n\t\tfor(j=0;j='a'&&c[j]<'z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='z')\n\t\t\t\tc[j]='a';\n\t\t\tif(c[j]>='A'&&c[j]<'Z')\n\t\t\t\tc[j]+=1;\n\t\t\telse if(c[j]=='Z')\n\t\t\t\tc[j]='A';\n\t\t}\n\t\tfp=fopen(f,\"w\");\n\t\tfputs(c,fp);\n\t\tfclose(fp);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470256", + "status": 0, + "keywords": "密码破解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/23.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/24.json b/data_backup/cpp_code_json/24.json new file mode 100644 index 000000000..962c77a76 --- /dev/null +++ b/data_backup/cpp_code_json/24.json @@ -0,0 +1,18 @@ +{ + "question_id": 7449253, + "question_title": "数学题", + "question_content": "编程求1-200中能被2、3、5除余1的前10个整数。", + "difficulty": "简单", + "answer_id": 53429293, + "answer_content": "
\n#include <stdio.h>\nint main()\n{\n    int n=0,i;\n    for(i=1; i<=200; i++)\n    {\n        if((i%2==1)&&(i%3==1)&&(i%5==1))\n        {\n            n++;\n            if(n<=10)\n                printf("%d ",i);\n            if(n==10)\n                break;\n\n        }\n    }\n}\n
\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint n=0,i;\n\tfor(i=1; i<=200; i++)\n\t{\n\t\tif((i%2==1)&&(i%3==1)&&(i%5==1))\n\t\t{\n\t\t\tn++;\n\t\t\tif(n<=10)\n\t\t\t\tprintf(\"%d \",i);\n\t\t\tif(n==10)\n\t\t\t\tbreak;\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469938", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/24.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/25.json b/data_backup/cpp_code_json/25.json new file mode 100644 index 000000000..de2b5cb55 --- /dev/null +++ b/data_backup/cpp_code_json/25.json @@ -0,0 +1,18 @@ +{ + "question_id": 7460385, + "question_title": "最小公倍数", + "question_content": "

从键盘输入两个正整数,求出它们的最小公倍数并输出所求结果。

", + "difficulty": "简单", + "answer_id": 53445460, + "answer_content": "

#include<stdio.h>
\nint main() {
\n    int m,n,temp,i;
\n    scanf("%d%d",&m,&n);
\n    if(m<n) /*比较大小,使得m中存储大数,n中存储小数*/
\n    {
\n        temp = m;
\n        m = n;
\n        n = temp;
\n    }
\n    for(i=m; i>0; i++)  /*从大数开始寻找满足条件的自然数*/
\n        if(i%m==0 && i%n==0)
\n        {/*输出满足条件的自然数并结束循环*/
\n            printf("%d 和 %d 的最小公倍数是: %d\\n", m, n, i);
\n            break;
\n        }
\n    return 0;
\n}

\n\n

私发点红就更好啦

\n", + "tag_name": "c语言", + "cpp": "#include\nint main() {\n    int m,n,temp,i;\n    scanf(\"%d%d\",&m,&n);\n    if(m0; i++)  \n        if(i%m==0 && i%n==0)\n        {\n            printf(\"%d 和 %d 的最小公倍数是: %d\\n\", m, n, i);\n            break;\n        }\n    return 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470147", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/25.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/26.json b/data_backup/cpp_code_json/26.json new file mode 100644 index 000000000..9320b00bd --- /dev/null +++ b/data_backup/cpp_code_json/26.json @@ -0,0 +1,18 @@ +{ + "question_id": 702202, + "question_title": "结合两个字符串", + "question_content": "写一个结合两个字符串的方法,从第一个字符串中取出一个字符,然后从第二个字符串中取出一个字符,以此类推。一旦一个字符串没有字符,它就应该继续使用另一个字符串\n输入:两个字符串,如s1=\"day\"和s2=\"time\"\n输出:一个结果字符串,对于上面的输入情况,它将是“dtaiyme”。", + "difficulty": "困难", + "answer_id": 592511, + "answer_content": "#include\n#include\nusing namespace std;\nstring StrCon(const string& a, const string& b)\n{\n\tstring c;\n\tint n = a.size(), m = b.size();\n\tif (0 == n)\treturn a;\n\tif (0 == m) return b;\n\tint i, j;\n\tfor (i = 0, j = 0; i < n && j < m; ++i, ++j)\n\t{\n\t\tc += a[i];\n\t\tc += b[i];\n\t}\n\twhile (i < n)\n\t\tc += a[i++];\n\twhile (j < m)\n\t\tc += b[j++];\n\treturn c;\n}\nint main()\n{\n\tstring s = \"day\", t = \"time\";\n\tcout << StrCon(s, t) << endl;\n\tsystem(\"pause\");\n\treturn 0;\n}\n\n```\n \n```\n\n", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nstring StrCon(const string& a, const string& b)\n{\n\tstring c;\n\tint n = a.size(), m = b.size();\n\tif (0 == n)\treturn a;\n\tif (0 == m) return b;\n\tint i, j;\n\tfor (i = 0, j = 0; i < n && j < m; ++i, ++j)\n\t{\n\t\tc += a[i];\n\t\tc += b[i];\n\t}\n\twhile (i < n)\n\t\tc += a[i++];\n\twhile (j < m)\n\t\tc += b[j++];\n\treturn c;\n}\nint main()\n{\n\tstring s = \"day\", t = \"time\";\n\tcout << StrCon(s, t) << endl;\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469844", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/26.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/27.json b/data_backup/cpp_code_json/27.json new file mode 100644 index 000000000..8aeada9c7 --- /dev/null +++ b/data_backup/cpp_code_json/27.json @@ -0,0 +1,18 @@ +{ + "question_id": 7429148, + "question_title": "if else 和 switch 使用", + "question_content": "

输入学生成绩,\n若成绩在95分以上,输出“A”;\n若成绩在85~94分,输出“B”;\n若成绩在75~84分,输出“C”;\n若成绩在65~74分,输出“D”;\n若成绩在65分以下,输出“E”。(分别用if else 和 switch 语句完成)

", + "difficulty": "简单", + "answer_id": 53395657, + "answer_content": "
\n#include "stdio.h" \n/*\n输入学生成绩,\n若成绩在95分以上,输出“A”;\n若成绩在85~94分,输出“B”;\n若成绩在75~84分,输出“C”;\n若成绩在65~74分,输出“D”;\n若成绩在65分以下,输出“E”。(分别用if else 和 switch 语句完成)\n*/\nint main(){\n\tint score;\n\t\n\tscanf("%d",&score);\n\tif(score>=95){\n\t\tprintf("A\\n");\t\n\t}else if(score>=85 && score<=94){\n\t\tprintf("B\\n");\n\t}else if(score>=75 && score<=84){\n\t\tprintf("C\\n");\n\t}else if(score>=65 && score<=74){\n\t\tprintf("D\\n");\n\t}else{\n\t\tprintf("E\\n");\n\t}\n\t\n\tprintf("以下用switch语句实现相同功能\\n");\n\tscore = score-5;\n\tscore = score/10;\n\tswitch(score){\n\t\tcase 9:\n\t\t\tprintf("A\\n");\t\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tprintf("B");\t\n\t\t\tbreak;\n\t\tcase 7:\n\t\t\tprintf("C\\n");\t\n\t\t\tbreak;\n\t\tcase 6:\n\t\t\tprintf("D\\n");\t\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tprintf("E\\n");\n\t\t\tbreak;\n\t}\n\t\n\t\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \"stdio.h\" \nint main(){\n\tint score;\n\tscanf(\"%d\",&score);\n\tif(score>=95){\n\t\tprintf(\"A\\n\");\t\n\t}else if(score>=85 && score<=94){\n\t\tprintf(\"B\\n\");\n\t}else if(score>=75 && score<=84){\n\t\tprintf(\"C\\n\");\n\t}else if(score>=65 && score<=74){\n\t\tprintf(\"D\\n\");\n\t}else{\n\t\tprintf(\"E\\n\");\n\t}\n\tprintf(\"以下用switch语句实现相同功能\\n\");\n\tscore = score-5;\n\tscore = score/10;\n\tswitch(score){\n\t\tcase 9:\n\t\t\tprintf(\"A\\n\");\t\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tprintf(\"B\");\t\n\t\t\tbreak;\n\t\tcase 7:\n\t\t\tprintf(\"C\\n\");\t\n\t\t\tbreak;\n\t\tcase 6:\n\t\t\tprintf(\"D\\n\");\t\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tprintf(\"E\\n\");\n\t\t\tbreak;\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470148", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/27.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/28.json b/data_backup/cpp_code_json/28.json new file mode 100644 index 000000000..b037b3f75 --- /dev/null +++ b/data_backup/cpp_code_json/28.json @@ -0,0 +1,17 @@ +{ + "question_id": 7439547, + "question_title": "链表问题", + "question_content": "

1. 有一个有序的数组。现输入一个数,要求按原来的规律将它插入数组中(使用指针实现)。

\n\n

【样例输入】

\n\n

7

\n\n

【样例输出】

\n\n

26 18 16 14 12 9 8 7 6 4 3

", + "difficulty": "中等", + "answer_id": 53414064, + "answer_content": "

\"\"

\n\n
\n#include<iostream>\nusing namespace std;\n#define length 10\n\nint main(){\n\tint *m = new int();\n\tcin>>*m;\n\tint a[length] = {26,18,16,14,12,9,8,6,4,3};\n\tint *b = a;\n\tint *c = a;\n\tint i, j;\n\tfor(i = 0; i < length; i++){\n\t\tif(*m > *b){\n\t\t\tbreak;\n\t\t}\n\t\tb++;\n\t}\n\tfor(j = length; j > i; j--){\n\t\t*(b-i+j) = *(b-i+j-1);\n\t}\n\t*b = *m;\n\tfor(j = 0; j < length+1; j++){\n\t\tcout<<*(c++)<<' ';\n\t}\n\treturn 0;\n} 
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include\nusing namespace std;\n#define length 10\nint main(){\n\tint *m = new int();\n\tcin>>*m;\n\tint a[length] = {26,18,16,14,12,9,8,6,4,3};\n\tint *b = a;\n\tint *c = a;\n\tint i, j;\n\tfor(i = 0; i < length; i++){\n\t\tif(*m > *b){\n\t\t\tbreak;\n\t\t}\n\t\tb++;\n\t}\n\tfor(j = length; j > i; j--){\n\t\t*(b-i+j) = *(b-i+j-1);\n\t}\n\t*b = *m;\n\tfor(j = 0; j < length+1; j++){\n\t\tcout<<*(c++)<<' ';\n\t}\n\treturn 0;\n} ", + "topic_link": "https://bbs.csdn.net/topics/600469939", + "status": 0, + "keywords": "链表,算法中阶,数据结构,基本数据结构", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/28.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/29.json b/data_backup/cpp_code_json/29.json new file mode 100644 index 000000000..41b8bc90f --- /dev/null +++ b/data_backup/cpp_code_json/29.json @@ -0,0 +1,18 @@ +{ + "question_id": 1019861, + "question_title": "最优路线", + "question_content": "题目描述\n探险队要穿越泥潭,必须选择可踩踏的落脚点。可是泥潭面积很大,落脚点又实在少得可怜,一不小心就会深陷泥潭而无法脱身。侦查员费尽周折才从老乡手里弄到了一份地图,图中标出了落脚点的位置,而且令人震惊的是:泥潭只有一条穿越路线,且对于 n×m 的地图,路线长度为 n+m-1!请编程为探险队找出穿越路线。\n输入描述\n两个整数 n 和 m,表示泥潭的长和宽。下面 n 行 m 列表示地形(0 表示泥潭,1 表示落脚点)\n输出描述\n用坐标表示穿越路线,坐标之间用 > 分隔\n样例输入\n6 9\n1 1 1 0 0 0 0 0 0\n0 0 1 1 1 0 0 0 0\n0 0 0 0 1 0 0 0 0\n0 0 0 0 1 1 0 0 0\n0 0 0 0 0 1 1 1 1\n0 0 0 0 0 0 0 0 1\n样例输出\n(1,1)>(1,2)>(1,3)>(2,3)>(2,4)>(2,5)>(3,5)>(4,5)>(4,6)>(5,6)>(5,7)>(5,8)>(5,9)>(6,9)", + "difficulty": "困难", + "answer_id": 1211665, + "answer_content": "https://www.cnblogs.com/acmblog/p/9481082.html\n\n\n```\n#include \n#include \nconst int N=101;\nint map[N][N];\nint n,m;\nstruct point{\n int l,r;\n}node[N];//结构体数组用来存储路径\nint ans;\nvoid DFS(int x,int y)//这是深度优先搜索实现过程,本质就是一个递归的过程\n{\n if(x==n&&y==m)\n {\n for(int i=1;i\n#include \nconst int N=101;\nint map[N][N];\nint n,m;\nstruct point{\n\tint l,r;\n}node[N];\nint ans;\nvoid DFS(int x,int y)\n{\n\tif(x==n&&y==m)\n\t{\n\t\tfor(int i=1;i\", node[i].l, node[i].r);\n\t\tprintf(\"(%d,%d)\\n\", x, y);\n\t}\n\telse{\n\t\tif(map[x][y]==1&&x<=n&&y<=m)\n\t\t{\n\t\t\tnode[ans].l=x;\n\t\t\tnode[ans].r=y;\n\t\t\tans++;\n\t\t\tDFS(x+1,y);\n\t\t\tDFS(x,y+1);\n\t\t}\n\t}\n}\nint main()\n{\n\twhile(scanf(\"%d%d\", &n, &m) != EOF)\n\t{\n\t\tans=1;\n\t\tmemset(map,0,sizeof(map));\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t\tscanf(\"%d\", &map[i][j]);\n\t\tDFS(1,1);\t\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470149", + "status": 1, + "keywords": "图算法,算法高阶,图的表示,基本的图算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/29.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/3.json b/data_backup/cpp_code_json/3.json new file mode 100644 index 000000000..ac124b7ec --- /dev/null +++ b/data_backup/cpp_code_json/3.json @@ -0,0 +1,18 @@ +{ + "question_id": 7455894, + "question_title": "任意输入10数,存入数组,找出显示最大值,并且标记所在位置。", + "question_content": "任意输入10数,存入数组,找出显示最大值,并且标记所在位置。", + "difficulty": "简单", + "answer_id": 53439230, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\nint main()\n{\n\tint a[10],i,max,maxindex;\n\tfor(i =0;i<10;i++)\n\t\tscanf("%d",&a[i]);\n\n\t//找最大的数\n\tmax = a[0];  //先将最大的数设为0\n\tmaxindex = 0;//最大的数的索引\n\tfor (i =1;i<10;i++)\n\t{\n\t\tif(a[i] > max)\n\t\t{\n\t\t\tmax = a[i];    //替换最大值\n\t\t\tmaxindex = i;  //记录最大值索引\n\t\t}\n\t}\n\tprintf("最大值%d,索引:%d\\n",max,maxindex);\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint a[10],i,max,maxindex;\n\tfor(i =0;i<10;i++)\n\t\tscanf(\"%d\",&a[i]);\n\tmax = a[0]; \n\tmaxindex = 0;\n\tfor (i =1;i<10;i++)\n\t{\n\t\tif(a[i] > max)\n\t\t{\n\t\t\tmax = a[i];\t\n\t\t\tmaxindex = i; \n\t\t}\n\t}\n\tprintf(\"最大值%d,索引:%d\\n\",max,maxindex);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469936", + "status": 1, + "keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/3.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/30.json b/data_backup/cpp_code_json/30.json new file mode 100644 index 000000000..18d6aa0bc --- /dev/null +++ b/data_backup/cpp_code_json/30.json @@ -0,0 +1,18 @@ +{ + "question_id": 7443359, + "question_title": "数组排序", + "question_content": "

给定n(n是偶数,且n≤100)个正整数,所有正整数均≤10000;从前往后依次遍历这个数组,每两个为一组进行处理,若一组中的任意一个元素能被3或者5整除,则交换这两个元素的位置;否则不动;全部处理完成后,逆序输出整个数组。\n例如给定序列: 99 35 83 38 , 处理完成后得到:38 83 99 35\n给定序列: 6 7 3 4 ,处理完成后得到:3 4 6 7

", + "difficulty": "困难", + "answer_id": 53420448, + "answer_content": "
\n#include <stdio.h>\n#include <math.h>\n\nint main()\n{\n\nint i,j,n,a[10005],t;\nscanf("%d",&n);\nfor(i=0;i<n;i++){\n    scanf("%d",&a[i]);\n    if(i%2==1){\n        if((a[i]%3==0)||(a[i]%5==0)||(a[i-1]%3==0)||(a[i-1]%5==0)){\n            t=a[i];\n            a[i]=a[i-1];\n            a[i-1]=t;\n        }\n    }\n}\nfor(i=n-1;i>=0;i--){\n    printf("%d ",a[i]);\n}\n\n\n}
\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tint i,j,n,a[10005],t;\n\tscanf(\"%d\",&n);\n\tfor(i=0;i=0;i--){\n\t\tprintf(\"%d \",a[i]);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470257", + "status": 1, + "keywords": "算法初阶,基础知识,特征序列,概率分析和随机算法,概率分析和指示器随机变量的进一步使用", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/30.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/31.json b/data_backup/cpp_code_json/31.json new file mode 100644 index 000000000..ceffe989a --- /dev/null +++ b/data_backup/cpp_code_json/31.json @@ -0,0 +1,17 @@ +{ + "question_id": 702251, + "question_title": "字符拆分和 反转", + "question_content": "将IP\"1.1.168.192\"\n\t\t\t\t变换成 IP\"192.168.1.1\"\n\t\t\t\t只改\"\"内的\n\t\t\t\t返回string类型", + "difficulty": "中等", + "answer_id": 592646, + "answer_content": "\n\n```\n #include \n#include \n#include \n\nusing namespace std;\n\nvector split(const string &s, const string &seperator){\n vector result;\n typedef string::size_type string_size;\n string_size i = 0;\n \n while(i != s.size()){\n //找到字符串中首个不等于分隔符的字母;\n int flag = 0;\n while(i != s.size() && flag == 0){\n flag = 1;\n for(string_size x = 0; x < seperator.size(); ++x)\n if(s[i] == seperator[x]){\n ++i;\n flag = 0;\n break;\n }\n }\n \n //找到又一个分隔符,将两个分隔符之间的字符串取出;\n flag = 0;\n string_size j = i;\n while(j != s.size() && flag == 0){\n for(string_size x = 0; x < seperator.size(); ++x)\n if(s[j] == seperator[x]){\n flag = 1;\n break;\n }\n if(flag == 0) \n ++j;\n }\n if(i != j){\n result.push_back(s.substr(i, j-i));\n i = j;\n }\n }\n return result;\n}\n\nint main() {\n string s = \"1.1.168.192\";\n vector v = split(s, \".\");\n string result = v[v.size() - 1];\n for(vector::size_type i = v.size() - 2; i >= 0; i--)\n {\n result = result + \".\";\n\tresult = result + v[i];\n }\n cout << result;\n}\n```\n\n192.168.1.1", + "tag_name": "c++", + "cpp": " #include \n#include \n#include \nusing namespace std;\nvector split(const string &s, const string &seperator){\n vector result;\n typedef string::size_type string_size;\n string_size i = 0;\n while(i != s.size()){\n\tint flag = 0;\n\twhile(i != s.size() && flag == 0){\n\t flag = 1;\n\t for(string_size x = 0; x < seperator.size(); ++x)\n\t\tif(s[i] == seperator[x]){\n\t\t ++i;\n\t\t flag = 0;\n\t\t break;\n\t\t}\n\t}\n\tflag = 0;\n\tstring_size j = i;\n\twhile(j != s.size() && flag == 0){\n\t for(string_size x = 0; x < seperator.size(); ++x)\n\t\tif(s[j] == seperator[x]){\n\t\t flag = 1;\n\t\t break;\n\t\t}\n\t if(flag == 0) \n\t\t++j;\n\t}\n\tif(i != j){\n\t result.push_back(s.substr(i, j-i));\n\t i = j;\n\t}\n }\n return result;\n}\nint main() {\n string s = \"1.1.168.192\";\n vector v = split(s, \".\");\n string result = v[v.size() - 1];\n for(vector::size_type i = v.size() - 2; i >= 0; i--)\n {\n\tresult = result + \".\";\n\tresult = result + v[i];\n }\n cout << result;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469940", + "status": 0, + "keywords": "算法高阶,算法问题选编,多项式与快速傅里叶变换", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/31.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/32.json b/data_backup/cpp_code_json/32.json new file mode 100644 index 000000000..23cc3e5c7 --- /dev/null +++ b/data_backup/cpp_code_json/32.json @@ -0,0 +1,18 @@ +{ + "question_id": 1052907, + "question_title": "约分", + "question_content": "编写程序,要求用户输入一个分数,然后将其约分为最简式。如:\n输入一个分数:8/12\n最简分式:2/3", + "difficulty": "中等", + "answer_id": 1250263, + "answer_content": "我的思路是求出分子分母的最大公因数,分子分母同时除以最大公因数便得到了最简的分子与分母,代码如下:\n\n```\n\n```\n\n\n```\n#include\n#include\nint main()\n{\n int a,b,x,y,c;\n printf(\"输入一个分式:\");\n scanf(\"%d/%d\",&a,&b);\n if(a\n#include\nint main()\n{\n\tint a,b,x,y,c;\n\tprintf(\"输入一个分式:\");\n\tscanf(\"%d/%d\",&a,&b);\n\tif(a\nint main()\n{\nint ch[8];\nint ma[8];\nfor (int i = 0; i < 8; i++)\nscanf(\"%d%d\", &ch[i], &ma[i]);\nfor (int i = 0; i< 8; i++)\n{\nfor (int j = 0; j < 8; j++)\nif (ma[i] >= ma[j] && ch[i] >= ch[j])\nprintf(\"1 \");\nelse\nprintf(\"0 \");\nprintf(\"\\n\");\n}\nreturn 0;\n}\n```\n# 问题解决的话,请点下采纳", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint ch[8];\n\tint ma[8];\n\tfor (int i = 0; i < 8; i++)\n\t\tscanf(\"%d%d\", &ch[i], &ma[i]);\n\tfor (int i = 0; i< 8; i++)\n\t{\n\t\tfor (int j = 0; j < 8; j++)\n\t\t\tif (ma[i] >= ma[j] && ch[i] >= ch[j])\n\t\t\t\tprintf(\"1 \");\n\t\t\telse\n\t\t\t\tprintf(\"0 \");\n\t\tprintf(\"\\n\");\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469846", + "status": 1, + "keywords": "算法高阶,矩阵运算,矩阵求逆,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/33.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/34.json b/data_backup/cpp_code_json/34.json new file mode 100644 index 000000000..9e615c56f --- /dev/null +++ b/data_backup/cpp_code_json/34.json @@ -0,0 +1,18 @@ +{ + "question_id": 364242, + "question_title": "回文串", + "question_content": "题目描述\n回文串是从左到右或者从右到左读起来都一样的字符串,试编程判别一个字符串是否为回文串。\n输入\n输入一个字符串。串长度<255.\n输出\n判别输入的字符串是否为回文串,是回文串输出\"Y\",否则输出\"N\"。\n样例输入\nabcba\n样例输出\nY\n", + "difficulty": "简单", + "answer_id": 385629, + "answer_content": "\n\n```\n #include\n#include\nusing namespace std;\n\nint main(void)\n{\n char *p=\"abcba\";\n int n=strlen(p);\n bool flag=1;\n int i;\n for(i=0;i\n#include\nusing namespace std;\nint main(void)\n{\n\tchar *p=\"abcba\";\n\tint n=strlen(p);\n\tbool flag=1;\n\tint i;\n\tfor(i=0;i\nint fact(int n)\n{\nint r = 1;\nfor (int i = 1; i <= n; i++) r *= i;\nreturn r;\n}\nint main()\n{\nint m, n;\nscanf(\"%d%d\", &m, &n);\nint c = fact(n) / (fact(m) * fact(n - m));\nprintf(\"c=%d\", c);\nreturn 0;\n}\n```\n# 问题解决的话,请点下采纳", + "tag_name": "c语言", + "cpp": "#include \nint fact(int n)\n{\nint r = 1;\nfor (int i = 1; i <= n; i++) r *= i;\nreturn r;\n}\nint main()\n{\nint m, n;\nscanf(\"%d%d\", &m, &n);\nint c = fact(n) / (fact(m) * fact(n - m));\nprintf(\"c=%d\", c);\nreturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470150", + "status": 0, + "keywords": "算法中阶,摊还分析,聚合分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/35.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/36.json b/data_backup/cpp_code_json/36.json new file mode 100644 index 000000000..1bae8f396 --- /dev/null +++ b/data_backup/cpp_code_json/36.json @@ -0,0 +1,18 @@ +{ + "question_id": 7446622, + "question_title": "计算所有4位正整数中同时能被13和20整除的数的和", + "question_content": "

计算所有4位正整数中同时能被13和20整除的数的和, 并同时做到如下显示:\n①显示这些数:\n②显示这些数的个数:\n③显示这些数的和。

", + "difficulty": "简单", + "answer_id": 53426095, + "answer_content": "

代码:

\n\n
\n#include "stdio.h"\n\nint main()\n{\n\tint i = 1000;\n\tint count = 0;\n\tint sum = 0;\n\tprintf("所有4位正整数中同时能被13和20整除的数:\\n");\n\tfor(i = 1000;i<10000;i++)\n\t{\n\t\tif(i % 13 == 0 && i % 20 == 0)\n\t\t{\n\t\t\tcount++;\n\t\t\tsum = sum + i;\n\t\t\tprintf("%d、",i);\n\t\t}\n\t}\n\tprintf("\\n这些数一共有%d个\\n",count);\n\tprintf("这些数的和是:%d\\n",sum);\n}
\n\n

截图

\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \"stdio.h\"\nint main()\n{\n\tint i = 1000;\n\tint count = 0;\n\tint sum = 0;\n\tprintf(\"所有4位正整数中同时能被13和20整除的数:\\n\");\n\tfor(i = 1000;i<10000;i++)\n\t{\n\t\tif(i % 13 == 0 && i % 20 == 0)\n\t\t{\n\t\t\tcount++;\n\t\t\tsum = sum + i;\n\t\t\tprintf(\"%d、\",i);\n\t\t}\n\t}\n\tprintf(\"\\n这些数一共有%d个\\n\",count);\n\tprintf(\"这些数的和是:%d\\n\",sum);\n}", + "topic_link": "https://bbs.csdn.net/topics/600469942", + "status": 1, + "keywords": "算法高阶,计算几何学,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/36.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/37.json b/data_backup/cpp_code_json/37.json new file mode 100644 index 000000000..74664e7d9 --- /dev/null +++ b/data_backup/cpp_code_json/37.json @@ -0,0 +1,18 @@ +{ + "question_id": 7436555, + "question_title": "商品优惠计算器", + "question_content": "

商品优惠计算器\n使用if语句编程实现输入购货金额,输出实际付款金额。购货折扣率如下:\n购货金额≤500元 不打折\n500元<购货金额≤1000元 9折\n1000元<购货金额 8折

", + "difficulty": "简单", + "answer_id": 53408479, + "answer_content": "

 

\n\n
\n#include <stdio.h>\n#include <ctype.h>\n#include <stdbool.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\nint main()\n{\n\tfloat money=0.0;\n\tfloat pay=0.0;\n\t\n\tbool run = true;\n\twhile(run)\n\t{\n\t\tprintf("\\n请输入购货金额:\\n");\n\t\tscanf("%f", &money);\n\t\tif(money >=1000)\n\t\t{\n\t\t\tpay=money*0.8;\n\t\t\tprintf("打八折,应付金额:%.2f\\n",pay);\n\t\t}\n\t\telse if((money >500)&&(money <=1000))\n\t\t{\n\t\t\tpay=money*0.9;\n\t\t\tprintf("打九折,应付金额:%.2f\\n",pay);\n\t\t}\n\t\telse if(money <=500)\n\t\t{\n\t\t\tprintf("不打折,应付金额:%.2f\\n",money);\n\t\t}\n\t}\n\t\n\treturn 0;\n\n}
\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \n#include \n#include \n#include \n#include \nint main()\n{\n\tfloat money=0.0;\n\tfloat pay=0.0;\n\tbool run = true;\n\twhile(run)\n\t{\n\t\tprintf(\"\\n请输入购货金额:\\n\");\n\t\tscanf(\"%f\", &money);\n\t\tif(money >1000)\n\t\t{\n\t\t\tpay=money*0.8;\n\t\t\tprintf(\"打八折,应付金额:%.2f\\n\",pay);\n\t\t}\n\t\telse if((money >500)&&(money <=1000))\n\t\t{\n\t\t\tpay=money*0.9;\n\t\t\tprintf(\"打九折,应付金额:%.2f\\n\",pay);\n\t\t}\n\t\telse if(money <=500)\n\t\t{\n\t\t\tprintf(\"不打折,应付金额:%.2f\\n\",money);\n\t\t}\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470151", + "status": 1, + "keywords": "数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/37.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/38.json b/data_backup/cpp_code_json/38.json new file mode 100644 index 000000000..acda1151a --- /dev/null +++ b/data_backup/cpp_code_json/38.json @@ -0,0 +1,17 @@ +{ + "question_id": 7437679, + "question_title": "从一个字符串中找出最长的单词", + "question_content": "

#include<stdio.h>
\n#include<string.h>
\nint main()
\n{
\n    //void max(char[], char[]);
\n    char a[100], b[100],c[100];
\n    int i, j=  0, k = 0, n,m;
\n    gets(a);
\n    n = strlen(a);
\n    for (i = 0;  i<n; i++)
\n    {
\n        if ((a[i] >= 'A'&&a[i] <= 'Z') || (a[i] >= 'a'&&a[i] <= 'z'))
\n        {
\n            b[j++] = a[i];

\n\n

        }
\n    
\n        else if (j > k)
\n        {
\n            for (m = 0; m < j; m++)
\n                
\n            {
\n                c[m] = b[m];
\n                
\n            }
\n            k = m;
\n        
\n            j = 0;

\n\n

        }
\n        else if (j <= k)
\n            j = 0;

\n\n


\n    }
\n    c[k] = '\\0';
\n    printf("%s", c);

\n\n


\n}

\n\n

 

", + "difficulty": "中等", + "answer_id": 53410843, + "answer_content": "

楼主的代码修改如下,供参考:

\n\n
\n#include<stdio.h>\n#include<string.h>\nint main()\n{\n    //void max(char[], char[]);\n    char a[100], b[100],c[100];\n    int i, j=0, k=0, n,m;\n    gets(a);\n    n = strlen(a);\n    for (i = 0;  i<n+1; i++)//for (i = 0;  i<n; i++)\n    {\n        if ((a[i] >= 'A'&&a[i] <= 'Z') || (a[i] >= 'a'&&a[i] <= 'z'))\n        {\n            b[j++] = a[i];\n        }\n\n        else if (j > k)\n        {\n            for (m = 0; m < j; m++)\n\n            {\n                c[m] = b[m];\n\n            }\n            k = j;//k = m;\n            j = 0;\n\n        }\n        else if (j <= k)\n            j = 0;\n\n\n    }\n    c[k] = '\\0';\n    printf("%s\\n", c);\n    \n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include\n#include\nint main()\n{\n\tchar a[100], b[100],c[100];\n\tint i, j=0, k=0, n,m;\n\tgets(a);\n\tn = strlen(a);\n\tfor (i = 0; i= 'A'&&a[i] <= 'Z') || (a[i] >= 'a'&&a[i] <= 'z'))\n\t\t{\n\t\t\tb[j++] = a[i];\n\t\t}\n\t\telse if (j > k)\n\t\t{\n\t\t\tfor (m = 0; m < j; m++)\n\t\t\t{\n\t\t\t\tc[m] = b[m];\n\t\t\t}\n\t\t\tk = j;\n\t\t\tj = 0;\n\t\t}\n\t\telse if (j <= k)\n\t\t\tj = 0;\n\t}\n\tc[k] = '\\0';\n\tprintf(\"%s\\n\", c);\n}", + "topic_link": "https://bbs.csdn.net/topics/600469847", + "status": 0, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/38.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/39.json b/data_backup/cpp_code_json/39.json new file mode 100644 index 000000000..83c36bb3e --- /dev/null +++ b/data_backup/cpp_code_json/39.json @@ -0,0 +1,18 @@ +{ + "question_id": 876769, + "question_title": "求前n个素数之和", + "question_content": "题目描述\n求前n个素数的和。 \n例如,前5个素数是2、3、5、7、11,它们的和是28。 \n输入\n一个整数n,1<=n<=1000。 \n输出\n前n个素数的和 \n样例输入\n5\n样例输出\n28\n提示\n第1000个素数是7919。\n", + "difficulty": "中等", + "answer_id": 1011802, + "answer_content": "你的a是数组,a++是非法的\n\n```\n#include \nusing namespace std;\nint main()\n{\n int n,i,j,sum,a;\n cin>>n;\n\n a = 0;\n i = 2;\n sum=0;\n while(a\nusing namespace std;\nint main()\n{\n\tint n,i,j,sum,a;\n\tcin>>n;\n\ta = 0;\n\ti = 2;\n\tsum=0;\n\twhile(a\n#include <stdio.h>\n \n#define ARR_LEN 255 /*数组长度上限*/\n#define elemType int /*元素类型*/\n \n/* 冒泡排序 */\n/* 1. 从当前元素起,向后依次比较每一对相邻元素,若逆序则交换 */\n/* 2. 对所有元素均重复以上步骤,直至最后一个元素 */\n/* elemType arr[]: 排序目标数组; int len: 元素个数 */\nvoid bubbleSort (elemType arr[], int len) {\n elemType temp;\n int i, j;\n for (i=0; i<len-1; i++) /* 外循环为排序趟数,len个数进行len-1趟 */\n for (j=0; j<len-1-i; j++) { /* 内循环为每趟比较的次数,第i趟比较len-i次 */\n if (arr[j] > arr[j+1]) { /* 相邻元素比较,若逆序则交换(升序为左大于右,降序反之) */\n temp = arr[j];\n arr[j] = arr[j+1];\n arr[j+1] = temp;\n }\n }\n}\n \nint main (void) {\n elemType arr[ARR_LEN] = {4286,3185,2895,3550,2745};\n int len = 5;\n int i;\n \n bubbleSort (arr, len);\n for (i=0; i<len; i++)\n printf ("%d\\t", arr[i]);\n putchar ('\\n');\n \n return 0;\n}\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#define ARR_LEN 255 \n#define elemType int \nvoid bubbleSort (elemType arr[], int len) {\n\telemType temp;\n\tint i, j;\n\tfor (i=0; i arr[j+1]) { \n\t\t\t\ttemp = arr[j];\n\t\t\t\tarr[j] = arr[j+1];\n\t\t\t\tarr[j+1] = temp;\n\t\t\t}\n\t\t}\n}\nint main (void) {\n\telemType arr[ARR_LEN] = {4286,3185,2895,3550,2745};\n\tint len = 5;\n\tint i;\n\tbubbleSort (arr, len);\n\tfor (i=0; i在一个数组A中存放100个数据,用子函数判断该数组中哪些是素数,并统计该素数的个数,在主函数中输出该素数的个数

", + "difficulty": "简单", + "answer_id": 53436453, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n#include <stdlib.h>\n\nint isPrime(int n)\n{\n\tint i = 2;\n\tif(n<2) return 0;\n\tfor (i=2;i<n;i++)\n\t{\n\t\tif(n%i == 0)\n\t\t\treturn 0;\n\t}\n\treturn 1;\n}\n\nint CountPrime(int a[],int size)\n{\n\tint i =0,count = 0;\n\t//统计素数个数\n\tfor (i = 0;i<size;i++)\n\t{\n\t\tif(isPrime(a[i]))\n\t\t{\n\t\t\tprintf("%d ",a[i]);\n\t\t\tcount++;\n\t\t\tif(count%10 == 0) //每10个一行\n\t\t\t\tprintf("\\n");\n\t\t}\n\t}\n\tprintf("\\n");\n\treturn count;\n}\n\nint main()\n{\n\tint a[100],i,count = 0;\n\tfor(i = 0;i<100;i++)\n\t\ta[i] = rand()%1000;//生成0-999以内的随机数\n\t\n\tprintf("素数的个数:%d\\n",CountPrime(a,100));\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nint isPrime(int n)\n{\n\tint i = 2;\n\tif(n<2) return 0;\n\tfor (i=2;i实现从键盘输入一个字符时,如果该字符为小写字母,则转换为大写字母输出;如果该字符为大写字母,则转换为小写字母输出;如果为其他字符,则原样输出。

", + "difficulty": "简单", + "answer_id": 53408453, + "answer_content": "
\n#include<stdio.h>\nint main()\n{\nchar x,y;\nprintf("请输入一个字符:");\nscanf("%c",&x);\nif(x>='A'&&x<='Z')\n{\ny=x+32;\nprintf("此字母是一个大写字母,转换后的小写字母是:%c",y);\n}\nelse if(x>='a'&&x<='z')\n{\ny=x-32;\nprintf("此字母是一个小写字母,转换后的大写字母是%c",y);\n}\nelse\n{\nprintf("%c",x);\n}\nreturn 0;\n}\n
\n\n

记得点个采纳,谢谢 

\n", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tchar x,y;\n\tprintf(\"请输入一个字符:\");\n\tscanf(\"%c\",&x);\n\tif(x>='A'&&x<='Z')\n\t{\n\t\ty=x+32;\n\t\tprintf(\"此字母是一个大写字母,转换后的小写字母是:%c\",y);\n\t}\n\telse if(x>='a'&&x<='z')\n\t{\n\t\ty=x-32;\n\t\tprintf(\"此字母是一个小写字母,转换后的大写字母是%c\",y);\n\t}\n\telse\n\t{\n\t\tprintf(\"%c\",x);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469945", + "status": 1, + "keywords": "算法高阶,递归结构,高级数据结构,van Emde Boas树,原型van Emde Boas结构", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/41.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/42.json b/data_backup/cpp_code_json/42.json new file mode 100644 index 000000000..a824897b4 --- /dev/null +++ b/data_backup/cpp_code_json/42.json @@ -0,0 +1,18 @@ +{ + "question_id": 717268, + "question_title": "从键盘输入一组数据建立单链表,然后输出奇数位上的元素。", + "question_content": "输入\n第一行输入单链表长度n。\n第二行输入字符串。\n输出\n第一行:输出各奇数位元素\n样例输入\n7\nABCDEFG\n样例输出\nACEG", + "difficulty": "简单", + "answer_id": 710446, + "answer_content": "\n```\n#include \"stdio.h\"\n#include \"stdlib.h\"\n\ntypedef struct node\n{\n\tchar x;\n\tnode * next;\n} LList;\n\nint main()\n{\n\tLList * header = NULL;\n\tnode * p;\n\tint n;\n\tscanf(\"%d\", &n);\n\tfflush(stdin);\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tif (!header) \n\t\t{\n\t\t\theader = (node *)malloc(sizeof(node));\n\t\t\tp = header;\n\t\t\tscanf(\"%c\", &(header->x));\n\t\t\theader->next = NULL;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tp->next = (node *)malloc(sizeof(node));\n\t\t\tp = p->next;\n\t\t\tscanf(\"%c\", &(p->x));\n\t\t\tp->next = NULL;\n\t\t}\n\t}\n\tp = header;\n\tint i = 0;\n\twhile (p)\n\t{\n\t\tif (i++ % 2 == 0)\n\t\t\tprintf(\"%c\", p->x);\n\t\tp = p->next;\n\t}\n\treturn 0;\n}\n\n\n```\n\n![图片说明](https://img-ask.csdn.net/upload/201812/16/1544968420_383190.gif)\n", + "tag_name": "c语言", + "cpp": "#include \"stdio.h\"\n#include \"stdlib.h\"\ntypedef struct node\n{\n\tchar x;\n\tnode * next;\n} LList;\nint main()\n{\n\tLList * header = NULL;\n\tnode * p;\n\tint n;\n\tscanf(\"%d\", &n);\n\tfflush(stdin);\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tif (!header) \n\t\t{\n\t\t\theader = (node *)malloc(sizeof(node));\n\t\t\tp = header;\n\t\t\tscanf(\"%c\", &(header->x));\n\t\t\theader->next = NULL;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tp->next = (node *)malloc(sizeof(node));\n\t\t\tp = p->next;\n\t\t\tscanf(\"%c\", &(p->x));\n\t\t\tp->next = NULL;\n\t\t}\n\t}\n\tp = header;\n\tint i = 0;\n\twhile (p)\n\t{\n\t\tif (i++ % 2 == 0)\n\t\t\tprintf(\"%c\", p->x);\n\t\tp = p->next;\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470152", + "status": 1, + "keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/42.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/43.json b/data_backup/cpp_code_json/43.json new file mode 100644 index 000000000..5fc36258e --- /dev/null +++ b/data_backup/cpp_code_json/43.json @@ -0,0 +1,18 @@ +{ + "question_id": 7436247, + "question_title": "将其中每个单词的字母顺序翻转后打印输出到屏幕", + "question_content": "

初始化一个字符数组为"The best or nothing",并将其中每个单词的字母顺序翻转后打印输出到屏幕。要求:\n1、字符数组的初始化在程序运行时由用户输入;\n2、字符数组的翻转和结果输出功能通过函数实现;\n3、字符数组不能定义成全局变量。

", + "difficulty": "简单", + "answer_id": 53408492, + "answer_content": "

你要的结果是什么样的?

\n\n

输入:The best or nothing

\n\n

输出:ehT tseb ro gnihton

\n\n

这样的吗?如果是这样的,代码如下:

\n\n
\n#include <stdio.h>\n#include <string>\nvoid trans(char* p,int len)\n{\n\tchar* s = new char[len];\n\tmemcpy(s,p,len);\n\tfor (int i = 0; i < len; i++)\n\t{\n\t\tp[i] = s[len-1-i];\n\t}\n\tdelete[] s;\n\ts = 0;\n}\nvoid transfun(char* p,int len)\n{\n\tint start = 0;\n\tint i = 0;\n\tint shift = 0;\n\twhile(i < len)\n\t{\n\t\tfor (i = start; i < len;i++)\n\t\t{\n\t\t\tif(p[i] == ' ')\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\ttrans(p+shift,i-start);\n\t\tshift += i-start+1;\n\t\tstart = i+1;\n\t\ti +=1;\n\t}\n\t\t\n}\nvoid output(char* p)\n{\n\tprintf("%s\\n",p);\n}\nint main()\n{\n\tchar buf[1000] = {0};\n\tprintf("请输入字符串:");\n\tgets(buf);\n\ttransfun(buf,strlen(buf));\n\toutput(buf);\n\t//getchar();\n\t//getchar();\n\treturn 0;\n}\n
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nvoid trans(char* p,int len)\n{\n\tchar* s = new char[len];\n\tmemcpy(s,p,len);\n\tfor (int i = 0; i < len; i++)\n\t{\n\t\tp[i] = s[len-1-i];\n\t}\n\tdelete[] s;\n\ts = 0;\n}\nvoid transfun(char* p,int len)\n{\n\tint start = 0;\n\tint i = 0;\n\tint shift = 0;\n\twhile(i < len)\n\t{\n\t\tfor (i = start; i < len;i++)\n\t\t{\n\t\t\tif(p[i] == ' ')\n\t\t\t\tbreak;\n\t\t}\n\t\ttrans(p+shift,i-start);\n\t\tshift += i-start+1;\n\t\tstart = i+1;\n\t\ti +=1;\n\t}\n}\nvoid output(char* p)\n{\n\tprintf(\"%s\\n\",p);\n}\nint main()\n{\n\tchar buf[1000] = {0};\n\tprintf(\"请输入字符串:\");\n\tgets(buf);\n\ttransfun(buf,strlen(buf));\n\toutput(buf);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470153", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/43.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/44.json b/data_backup/cpp_code_json/44.json new file mode 100644 index 000000000..04b17a0e9 --- /dev/null +++ b/data_backup/cpp_code_json/44.json @@ -0,0 +1,18 @@ +{ + "question_id": 1072218, + "question_title": "商家商品销售量统计", + "question_content": "

现在有一个网站上半年的商品销售量,请你写一段代码帮助店主统计前半年的总销量和平均销量。\n商品销售表\n1月份\t2月份\t3月份\t4月份\t5月份\t6月份\t总销量\t平均销量\n64\t53\t77\t59\t61\t42\t0\t0\n(1)函数中应定义一个包含8个元素的一维数据,用来存放6个月的商品销量和统计后的总销量及平均销量;\n(2)完成6个月销量的输入;\n(3)计算半年的总销量及平均销量;\n(4)按照程序运行效果图,输出商品销量表。\n![图片说明](https://img-ask.csdn.net/upload/202005/16/1589596638_852927.jpg)

", + "difficulty": "简单", + "answer_id": 1274957, + "answer_content": "表格上可能有点不同,你可以再改改\n```\n#include\nint main()\n{\n\tint a[8],s=0;\n\tprintf(\"----------商家商品销售统计----------\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"请输入商品6个月的销售量:\");\n\tfor (int i = 0; i < 6; i++)\n\t{\n\t\tscanf(\"%d\", &a[i]);\n\t\ts += a[i];\n\t}\n\tprintf(\"\\n\\t\\t\\t商品销量表\\t\\t\\t\\n\");\n\tprintf(\"——————————————————————————————————————————————\\n\");\n\tfor (int i = 1; i <= 8; i++)\n\t{\n\t\tif (i <= 6)\n\t\t\tprintf(\" %d月份 \", i);\n\t\telse if (i == 7)\n\t\t\tprintf(\" 总销售 \");\n\t\telse\n\t\t\tprintf(\" 平均销售 \\n\");\n\t}\n\tfor (int i = 0; i < 8; i++)\n\t{\n\t\tif (i < 6)\n\t\t\tprintf(\" %d |\", a[i]);\n\t\telse if (i == 6)\n\t\t{\n\t\t\ta[i] = s;\n\t\t\tprintf(\" %d |\", a[i]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta[i] = s / 6;\n\t\t\tprintf(\" %d |\",a[i]);\n\t\t}\n\t}\n\treturn 0;\n}\n```\n![图片说明](https://img-ask.csdn.net/upload/202005/17/1589691710_74517.png)\n", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint a[8],s=0;\n\tprintf(\"----------商家商品销售统计----------\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"请输入商品6个月的销售量:\");\n\tfor (int i = 0; i < 6; i++)\n\t{\n\t\tscanf(\"%d\", &a[i]);\n\t\ts += a[i];\n\t}\n\tprintf(\"\\n\\t\\t\\t商品销量表\\t\\t\\t\\n\");\n\tprintf(\"——————————————————————————————————————————————\\n\");\n\tfor (int i = 1; i <= 8; i++)\n\t{\n\t\tif (i <= 6)\n\t\t\tprintf(\"\t%d月份 \", i);\n\t\telse if (i == 7)\n\t\t\tprintf(\"\t总销售 \");\n\t\telse\n\t\t\tprintf(\"\t平均销售 \\n\");\n\t}\n\tfor (int i = 0; i < 8; i++)\n\t{\n\t\tif (i < 6)\n\t\t\tprintf(\"\t %d |\", a[i]);\n\t\telse if (i == 6)\n\t\t{\n\t\t\ta[i] = s;\n\t\t\tprintf(\"\t %d |\", a[i]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta[i] = s / 6;\n\t\t\tprintf(\"\t %d |\",a[i]);\n\t\t}\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470258", + "status": 1, + "keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/44.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/45.json b/data_backup/cpp_code_json/45.json new file mode 100644 index 000000000..4b2278786 --- /dev/null +++ b/data_backup/cpp_code_json/45.json @@ -0,0 +1,18 @@ +{ + "question_id": 7458697, + "question_title": "求出最大分数和学号", + "question_content": "

【题目描述】\n输入一个班级的学生人数(学生人数不超过60人),再输入该班学生每个学生的学号和某门课的成绩,要求用函数编程实现输出最高分及其学号。\n【输入形式】\n第一行输入学生人数N,接下来的N行分别输入N个学生的学号和成绩,学号和成绩均为整数,学号范围为1~9999,成绩范围为0~100。\n【输出形式】\n一行,两个正整数,分别表示最高分和对应的学号。如果最高分有相同的,则输出最先出现的最高分和对应的学号。\n【样例输入1】\n3\n1101 85\n1102 95\n1103 90\n【样例输出1】\n95 1102

\n
\n#include<iostream>\n#include<cstring>\nusing namespace std;\nvoid findmax(int score[],int num[],int *pmax,int *pmaxnum);\nint main()\n{\n\tint n,i,max,maxnum;\n\tint score[100];\n\tchar num[100];\n\tcin>>n;//输入n \n\tfor(int i=0;i<n;i++)\n\t{\n\t\tcin>>num[i]>>score[i];//分别输入学号分数 \n\t}\n\tfindmax(score,num,n);//调用指针函数 \n} \nvoid findmax(int *score,char *num,int n)//找出最大分数和学号 \n{\n\tint max=*score;int maxnum=*num;//初始化最大分数和学号 \n\tfor(int i=0;i<n;i++)\n\t{\n\t\tif(score[i]>*max) \n\t\t{\n\t\t\t*pmax=score[i];\n\t\t\t*pmaxnum=num[i];\n\t\t}\n\t\t\n\t}\n\tcout<<*max<<" "<<*maxnum<<endl;\n\treturn 0;\n}
\n

 

", + "difficulty": "中等", + "answer_id": 53443352, + "answer_content": "

代码修改如下:

\n\n
\n#include<iostream>\n#include<cstring>\nusing namespace std;\nvoid findmax(int score[],int num[],int n,int &max,int &maxnum);\nint main()\n{\n\tint n,max,maxnum;\n\tint score[100];\n\tint num[100];\n\tcin>>n;//输入n \n\tfor(int i=0;i<n;i++)\n\t{\n\t\tcin>>num[i]>>score[i];//分别输入学号分数\n\t}\n\tfindmax(score,num,n,max,maxnum);//调用指针函数 \n} \nvoid findmax(int *score,int *num,int n,int &max,int &maxnum)//找出最大分数和学号 \n{\n\tmax=*score;\n\tmaxnum=*num;//初始化最大分数和学号 \n\tfor(int i=0;i<n;i++)\n\t{\n\t\tif(score[i]>max) \n\t\t{\n\t\t\tmax=score[i];\n\t\t\tmaxnum=num[i];\n\t\t}\n\t}\n\tcout<<max<<" "<<maxnum<<endl;\n\n}\n
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include\n#include\nusing namespace std;\nvoid findmax(int score[],int num[],int n,int &max,int &maxnum);\nint main()\n{\n\tint n,max,maxnum;\n\tint score[100];\n\tint num[100];\n\tcin>>n;\n\tfor(int i=0;i>num[i]>>score[i];\n\t}\n\tfindmax(score,num,n,max,maxnum);\n} \nvoid findmax(int *score,int *num,int n,int &max,int &maxnum)\n{\n\tmax=*score;\n\tmaxnum=*num;\n\tfor(int i=0;imax) \n\t\t{\n\t\t\tmax=score[i];\n\t\t\tmaxnum=num[i];\n\t\t}\n\t}\n\tcout<输入一个整数,将其按7进制位分解为各乘式的累加和(下图为输出结果)

\n

\"\"\n 

", + "difficulty": "简单", + "answer_id": 53424293, + "answer_content": "
\n#include<stdio.h>\n#define X 7\n\nint main()\n{\n    int i=0;\n    int mod,num=720;\n\n    while(num)\n    {\n        mod=num%X;\n        num/=X;\n        if(mod!=0)\n            printf("%d*7^%d%c",mod,i,(num>0)?'+':'\\n');\n        i++;\n    }\n\n    return 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include\n#define X 7\nint main()\n{\n\tint i=0;\n\tint mod,num=720;\n\twhile(num)\n\t{\n\t\tmod=num%X;\n\t\tnum/=X;\n\t\tif(mod!=0)\n\t\t\tprintf(\"%d*7^%d%c\",mod,i,(num>0)?'+':'\\n');\n\t\ti++;\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470155", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/46.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/47.json b/data_backup/cpp_code_json/47.json new file mode 100644 index 000000000..b5ec893af --- /dev/null +++ b/data_backup/cpp_code_json/47.json @@ -0,0 +1,18 @@ +{ + "question_id": 348590, + "question_title": "矩阵问题", + "question_content": "题目描述\n编写以下函数:\n(1)在一个二维数组中形成以下形式的n阶矩阵:\n[1 1 1 1 1\n2 1 1 1 1\n3 2 1 1 1\n4 3 2 1 1\n5 4 3 2 1]\n(2)去掉靠边的元素,生成新的n-2阶矩阵;\n(3)求生成的n阶矩阵主对角线上的元素之和;\n(4)以方阵形式输出数组。\n在main函数中调用以上函数进行测试。\n输入\n输入生成矩阵的阶数(n>=2)\n输出\n以方阵形式输出生成的n阶矩阵、去掉靠边的元素生成的新的n-2阶矩阵、以及生成的n阶矩阵主对角线上的元素之和,最后一行要回车\n样例输入\n5\n样例输出\nGenerated matrix:\n1 1 1 1 1\n2 1 1 1 1\n3 2 1 1 1\n4 3 2 1 1\n5 4 3 2 1\ndel the elements on the side:\n1 1 1\n2 1 1\n3 2 1\nThe sum of the diagonal:5\n", + "difficulty": "中等", + "answer_id": 355486, + "answer_content": "#include \n\n/* run this program using the console pauser or add your own getch, system(\"pause\") or input loop */\nusing namespace std; \nint main() {\nwhile(1){\n\n\tint a;\n\tcin>>a;//输入一个数 \n\tint array[a][a];//创建n阶数组 \n\tfor (int i=0;i= 1 ; i-- , j++)//对角 \n\t{\t\n\t\tsum+=array[i][j];//累加 \n\t}\n\tcout<<\"The sum of the diagonal:\"<\nusing namespace std; \nint main() {\n\twhile(1){\n\t\tint a;\n\t\tcin>>a;\n\t\tint array[a][a];\n\t\tfor (int i=0;i= 1 ; i-- , j++)\n\t\t{\t\n\t\t\tsum+=array[i][j];\n\t\t}\n\t\tcout<<\"The sum of the diagonal:\"<\n#include \nusing namespace std;\nstring a[1000];\nint main()\n{\n int i,n;\n cin>>n;\n for(i=1; i<=n; i++)\n {\n cin>>a[i];\n }\n for(i=1;i<=n;i++)\n\t{\n\t\tfor(int j=i+1;j<=n;j++)\n\t\t{\n\t\t\tif(a[i]>a[j])\n\t\t\t swap(a[i],a[j]);\n\t\t}\n\t}\n\tfor(int i=1;i<=n;i++)\n\t cout<\n#include \nusing namespace std;\nstring a[1000];\nint main()\n{\n\tint i,n;\n\tcin>>n;\n\tfor(i=1; i<=n; i++)\n\t{\n\t\tcin>>a[i];\n\t}\n\tfor(i=1;i<=n;i++)\n\t{\n\t\tfor(int j=i+1;j<=n;j++)\n\t\t{\n\t\t\tif(a[i]>a[j])\n\t\t\t\tswap(a[i],a[j]);\n\t\t}\n\t}\n\tfor(int i=1;i<=n;i++)\n\t\tcout<\n2、sum 值没有初始化;\n3、sum是局部变量,for语句执行完成就释放了,应该定位为static变量\n4、for循环中应添加相等的情况,也就是注意边界。\n\n正常程序如下:\n#include \nusing namespace std;\nint main()\n{\n\tint n; \n\tstatic int\tsum=1;\n\tcout << \"请输入N:\" << endl;\n\tcin >> n;\n\tfor (int i = 1; i <= n; i++)\n\t{\n\t\tfor (int j = 1; j <= i; j++)\n\t\t{\n\t\t\t\n\t\t\tsum = sum + j;\n\t\t\t\n\t\t}\n\t}\n\tcout << \"结果2为:\" << sum;\n\tsystem(\"pause\");\n\treturn 0;\n}\n", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint main()\n{\n\tint n; \n\tstatic int\tsum=1;\n\tcout << \"请输入N:\" << endl;\n\tcin >> n;\n\tfor (int i = 1; i <= n; i++)\n\t{\n\t\tfor (int j = 1; j <= i; j++)\n\t\t{\n\t\t\tsum = sum + j;\n\t\t}\n\t}\n\tcout << \"结果为:\" << sum;\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469946", + "status": 1, + "keywords": "数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/49.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/5.json b/data_backup/cpp_code_json/5.json new file mode 100644 index 000000000..e1426bf36 --- /dev/null +++ b/data_backup/cpp_code_json/5.json @@ -0,0 +1,18 @@ +{ + "question_id": 7462282, + "question_title": "对数组中所有的数据按照输入先后顺序进行显示输出", + "question_content": "

定义整数数组x,用键盘向数组输入10个数,输入之后,对数组中所有的数据按照输入先后顺序进行显示输出,最后设计一种算法,对数组中的数据进行升序排序,并输出排序后的数

\n", + "difficulty": "简单", + "answer_id": 53447798, + "answer_content": "

代码如下:如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n\nvoid Sortfun(double a[],int n)\n{\n\tint i,j;\n\tdouble tmp;\n\tfor (i=0;i<n-1;i++)\n\t{\n\t\tfor (j=0;j<n-1-i;j++)\n\t\t{\n\t\t\tif (a[j] > a[j+1])\n\t\t\t{\n\t\t\t\ttmp = a[j];\n\t\t\t\ta[j] = a[j+1];\n\t\t\t\ta[j+1]= tmp;\n\t\t\t}\n\t\t}\n\t}\n}\n\nint main()\n{\n\tint i;\n\tdouble a[10];\n\tprintf("请输入10个数:");\n\tfor(i =0;i<10;i++)\n\t\tscanf("%lf",&a[i]);\n\n\tprintf("原顺序:\\n");\n\tfor(i=0;i<10;i++)\n\t\tprintf("%g ",a[i]);\n\tprintf("\\n");\n\tSortfun(a,10);\n\n\tprintf("排序后:\\n");\n\tfor(i=0;i<10;i++)\n\t\tprintf("%g ",a[i]);\n\tprintf("\\n");\n\treturn 0;\n\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nvoid Sortfun(double a[],int n)\n{\n\tint i,j;\n\tdouble tmp;\n\tfor (i=0;i a[j+1])\n\t\t\t{\n\t\t\t\ttmp = a[j];\n\t\t\t\ta[j] = a[j+1];\n\t\t\t\ta[j+1]= tmp;\n\t\t\t}\n\t\t}\n\t}\n}\nint main()\n{\n\tint i;\n\tdouble a[10];\n\tprintf(\"请输入10个数:\");\n\tfor(i =0;i<10;i++)\n\t\tscanf(\"%lf\",&a[i]);\n\tprintf(\"原顺序:\\n\");\n\tfor(i=0;i<10;i++)\n\t\tprintf(\"%g \",a[i]);\n\tprintf(\"\\n\");\n\tSortfun(a,10);\n\tprintf(\"排序后:\\n\");\n\tfor(i=0;i<10;i++)\n\t\tprintf(\"%g \",a[i]);\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470244", + "status": 1, + "keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/5.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/50.json b/data_backup/cpp_code_json/50.json new file mode 100644 index 000000000..7a1fa0ca0 --- /dev/null +++ b/data_backup/cpp_code_json/50.json @@ -0,0 +1,18 @@ +{ + "question_id": 7426411, + "question_title": "字符串的处理", + "question_content": "

给定一个正整数N和一个由小写英文字母组成的长度N的字符串S。确定该字符串是否是某个字符串的两个副本的连接。也就是说,确定是否存在一个字符串T使S=T+T。如果S是某个字符串的两个副本的连接,则输出Yes;否则,直接输出No。\n例如,输入6(回车)abcabc,输出Yes(回车)Let T=abc,and S=T+T。\n或者输入4(回车)abac,输出No(回车)结束。

", + "difficulty": "简单", + "answer_id": 53389947, + "answer_content": "
\n#include <stdio.h>\nint main() {\n    int len,i,judge=0;\n    scanf("%d", &len);\n    char a[len+1];\n    scanf("%s", a);\n    if(len%2==0) {\n        for(i=0;i<(len/2);i++)\n            if(a[i]!=a[(len/2)+i]){\n                judge=1;\n                break;\n            }\n        if(judge==1)\n            printf("No");\n        else {\n            printf("Yes");\n        }\n    } else\n        printf("No");\n    printf("\\n");\n    return 0;\n}
\n\n

\"\"

", + "tag_name": "c语言", + "cpp": "#include \nint main() {\n\tint len,i,judge=0;\n\tscanf(\"%d\", &len);\n\tchar a[len+1];\n\tscanf(\"%s\", a);\n\tif(len%2==0) {\n\t\tfor(i=0;i<(len/2);i++)\n\t\t\tif(a[i]!=a[(len/2)+i]){\n\t\t\t\tjudge=1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif(judge==1)\n\t\t\tprintf(\"No\");\n\t\telse {\n\t\t\tprintf(\"Yes\");\n\t\t}\n\t} else\n\t\tprintf(\"No\");\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470157", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/50.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/51.json b/data_backup/cpp_code_json/51.json new file mode 100644 index 000000000..9c76cfa51 --- /dev/null +++ b/data_backup/cpp_code_json/51.json @@ -0,0 +1,18 @@ +{ + "question_id": 704613, + "question_title": "排序", + "question_content": "试题描述\n 由键盘上输入n个整数,请将这些数从大到小排序,然后输出排序后的数列。\n输入\n 输入包含两行:\n 第一行是n(1 <= n <= 1000)。\n 第二行是n个整数,邻近两数之间用一个空格隔开。\n输出\n 输出排序后的n个整数,邻近两数之间用一个空格隔开。\n输入示例\n 5\n 8 2 5 1 2\n输出示例\n 8 5 2 2 1\n数据范围\n 输入和输出均为int范围的整数", + "difficulty": "简单", + "answer_id": 598037, + "answer_content": "又是你.\n\n```\n #include\nusing namespace std;\nint main() {\n\tint n,tmp;\n\tcin >> n;\n\tint *a = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> a[i];\n\tfor (int i = 0; i < n - 1; i++) {\t\t//冒泡排序\n\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\tif (a[i] < a[j]) {\n\t\t\t\ttmp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < n; i++) {\n\t\tcout << a[i];\n\t\tif (i != n - 1)\n\t\t\tcout << \" \";\n\t}\n\treturn 0;\n}\n```\n\n", + "tag_name": "c++", + "cpp": " #include\nusing namespace std;\nint main() {\n\tint n,tmp;\n\tcin >> n;\n\tint *a = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t\tcin >> a[i];\n\tfor (int i = 0; i < n - 1; i++) {\t\t\n\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\tif (a[i] < a[j]) {\n\t\t\t\ttmp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < n; i++) {\n\t\tcout << a[i];\n\t\tif (i != n - 1)\n\t\t\tcout << \" \";\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470259", + "status": 1, + "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/51.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/52.json b/data_backup/cpp_code_json/52.json new file mode 100644 index 000000000..32e487eab --- /dev/null +++ b/data_backup/cpp_code_json/52.json @@ -0,0 +1,18 @@ +{ + "question_id": 7445111, + "question_title": "求数列的第n项的值", + "question_content": "已知数列:2,4,4,4,6,6,6,6,6,8,8,8,8,8,8,8,...求第n项的值", + "difficulty": "简单", + "answer_id": 53424084, + "answer_content": "

\"\"

\n\n
\n#include <iostream>\n\nint main()\n{\n    unsigned int N;\n    std::cout << "Please enter the value of N: ";\n    std::cin >> N;\n    if (N % 2 != 0)\n    {\n        std::cout << "Please enter an even number greater than zero!" << std::endl;\n        return -1;\n    }\n\n    int oddCount = 1;\n    int printCount = 0;\n    for (int i = 2; i <= N; i += 2)\n    {\n        for (int j = 0; j < oddCount; j++)\n        {\n            std::cout << i << " ";\n            printCount++;\n            if (printCount == N)\n            {\n                std::cout << "<---这个就是第N = " << N << "个数。" << std::endl;\n                return 0;\n            }\n        }\n\n        oddCount += 2;\n    }\n    return 0;\n}\n
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tunsigned int N;\n\tstd::cout << \"Please enter the value of N: \";\n\tstd::cin >> N;\n\tif (N % 2 != 0)\n\t{\n\t\tstd::cout << \"Please enter an even number greater than zero!\" << std::endl;\n\t\treturn -1;\n\t}\n\tint oddCount = 1;\n\tint printCount = 0;\n\tfor (int i = 2; i <= N; i += 2)\n\t{\n\t\tfor (int j = 0; j < oddCount; j++)\n\t\t{\n\t\t\tstd::cout << i << \" \";\n\t\t\tprintCount++;\n\t\t\tif (printCount == N)\n\t\t\t{\n\t\t\t\tstd::cout << \"<---这个就是第N = \" << N << \"个数。\" << std::endl;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\toddCount += 2;\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470260", + "status": 1, + "keywords": "递归,数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/52.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/53.json b/data_backup/cpp_code_json/53.json new file mode 100644 index 000000000..b62136e56 --- /dev/null +++ b/data_backup/cpp_code_json/53.json @@ -0,0 +1,18 @@ +{ + "question_id": 1061094, + "question_title": "难倒数万人的小学数学题", + "question_content": "汉堡包在大街上大摇大摆的走着,看着手机上一道难倒数万人的小学数学题:\n1 + 1 = 0\n1 + 6 = 1\n6 + 6 = 2\n8 + 1 = 2\n8 + 6 = 3\n汉堡包看完之后发现上面这些加法的答案就是看1,6,8中圈圈的个数嘛!\n突然之间,所有大厦上的LED屏幕上的广告全部变成数字1,6,8三个数字的随机闪现。\n现给你一块n*m的LED屏幕,上面有且仅有一个数字(1,6,or 8),请你输出你看见的那个字母。\n输入格式:\n第一行输入两个整数n,m(2<= m, n <= 1000);\n接下来n行,每行由m个数字0和1组成,其中1表示数字1,6,8的组成部分。\n输出格式:\n输出一个整数,代表图形表示的数字。\n输入样例:\n7 7\n0 0 0 0 0 0 0\n0 0 1 1 1 0 0\n0 0 1 0 1 0 0\n0 0 1 1 1 0 0\n0 0 1 0 1 0 0\n0 0 1 1 1 0 0\n0 0 0 0 0 0 0\n输出样例:\n8", + "difficulty": "中等", + "answer_id": 1258889, + "answer_content": "\n```\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint main(){\n int i,j,k=1;\n int n,m;\n int num[1010]={0};\n int num_cmp=0;\n int flag=1;\n int led[1005][1005];\n cin >> n >> m;\n for(i=1;i<=n;i++){\n for(j=1;j<=m;j++){\n cin >> led[i][j];\n if(led[i][j]==1) num[k]++;\n }\n if(num[k]!=0)k++;\n }\n num_cmp=num[k-1];\n for(i=k-1;i>0;i--){\n if(num[i]\n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint main(){\n\tint i,j,k=1;\n\tint n,m;\n\tint num[1010]={0};\n\tint num_cmp=0;\n\tint flag=1;\n\tint led[1005][1005];\n\tcin >> n >> m;\n\tfor(i=1;i<=n;i++){\n\t\tfor(j=1;j<=m;j++){\n\t\t\tcin >> led[i][j];\n\t\t\tif(led[i][j]==1) num[k]++;\n\t\t}\n\t\tif(num[k]!=0)k++;\n\t}\n\tnum_cmp=num[k-1];\n\tfor(i=k-1;i>0;i--){\n\t\tif(num[i]\nstruct book\n{\n float price;\n char a[30];\n};\nint main()\n{\n int n;\n scanf(\"%d\",&n);\n\n char a[30];\n\tint i,k,maxi=0,mini=0;\n\tbook b[10];\n for(i=0;ib[maxi].price)\n {\n maxi=i;\n }\n\t\tif(b[i].price\nstruct book\n{\n\tfloat price;\n\tchar a[30];\n};\nint main()\n{\n\tint n;\n\tscanf(\"%d\",&n);\n\tchar a[30];\n\tint i,k,maxi=0,mini=0;\n\tbook b[10];\n\tfor(i=0;ib[maxi].price)\n\t\t{\n\t\t\tmaxi=i;\n\t\t}\n\t\tif(b[i].price使用选择排序法对10个整数进行由大到小排序。

", + "difficulty": "简单", + "answer_id": 53409792, + "answer_content": "
\n\n#include <stdio.h>\nint main() {\n\tint a[10];\n\tint i,j,temp=0;\n\tint k,x=0;\n\tprintf("输入10个数:\\n");\n\tfor(i=0; i<10; i++)\n\t\tscanf("%d",&a[i]);\n\tfor(i=0; i<9; i++) {\n\t\tk = i;\n\t\tfor(j=i+1; j<10; j++)\n\t\t\tif(a[j]<a[i])\n\t\t\t\tk = j;\n\t\ttemp=a[i];\n\t\ta[i]=a[k];\n\t\ta[k]=temp;\n\t}\n\tprintf("排序后:\\n");\n\tfor(i=0; i<10; i++)\n\t\tprintf("%d ",a[i]);\n\tgetchar();\n\tgetchar();\n}
\n\n

代码如上,万望采纳。

\n", + "tag_name": "c语言", + "cpp": "#include \nint main() {\n\tint a[10];\n\tint i,j,temp=0;\n\tint k,x=0;\n\tprintf(\"输入10个数:\\n\");\n\tfor(i=0; i<10; i++)\n\t\tscanf(\"%d\",&a[i]);\n\tfor(i=0; i<9; i++) {\n\t\tk = i;\n\t\tfor(j=i+1; j<10; j++)\n\t\t\tif(a[j]![图片说明](https://img-ask.csdn.net/upload/202006/14/1592104139_240178.png)\n六角填数\n题目描述\n如下图所示六角形中,有12个点,依次填入1~12的数字,使得每条直线上的数字之和都相同。其中,已经替你填好了点1,2,3的数字,请你计算其他位置所代表的数字是多少?\n输入\n输入仅一行,以空格隔开,分别表示已经填好的点1,2,3的数字。\n输出\n输出仅一行,以空格隔开,分别表示所有位置所代表的数字。\n样例输入:\n1 8 2\n样例输出:\n1 8 2 9 7 11 10 12 3 5 6 4

", + "difficulty": "困难", + "answer_id": 1290115, + "answer_content": "\n```\n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define eps 10e-10\n#define N 15\n\nint a[N];\nbool vis[N];\n\nvoid dfs(int x){\n if(x == 1 || x == 2 || x == 3){\n dfs(x+1);\n return ;\n }\n if(x > 12){\n int t[6];\n t[0] = a[1] + a[3] + a[6] + a[8];\n t[1] = a[1] + a[4] + a[7] + a[11];\n t[2] = a[2] + a[3] + a[4] + a[5];\n t[3] = a[2] + a[6] + a[9] + a[12];\n t[4] = a[8] + a[9] + a[10] + a[11];\n t[5] = a[12] + a[10] + a[7] + a[5];\n\n for(int i = 1; i < 6; ++i){\n if(t[i] != t[i-1])return ;\n }\n\t\tfor (int i = 1; i <= 12; i++) cout << a[i] << \" \";\n return ;\n }\n\n for(int i = 1;i < 13; ++i){\n if(!vis[i]){\n vis[i] = 1;\n a[x] = i;\n dfs(x+1);\n vis[i] = 0;\n }\n }\n\n\n}\n\nint main(){\n memset(vis,0,sizeof(vis));\n cin >> a[1];\n\tvis[a[1]] = 1;\n cin >> a[2];\n\tvis[a[2]] = 1;\n cin >> a[3];\n\tvis[a[3]] = 1;\n dfs(1);\n return 0;\n}\n\n```\n![图片说明](https://img-ask.csdn.net/upload/202006/14/1592106523_783342.png)\n\n# lz你刚来,长点心吧,这里很多人看似在回答你问题,实际上都是投机取巧胡乱抄袭。\n", + "tag_name": "c++", + "cpp": "#include \n#include \n#include \n#include \nusing namespace std;\n#define eps 10e-10\n#define N 15\nint a[N];\nbool vis[N];\nvoid dfs(int x){\n\tif(x == 1 || x == 2 || x == 3){\n\t\tdfs(x+1);\n\t\treturn ;\n\t}\n\tif(x > 12){\n\t\tint t[6];\n\t\tt[0] = a[1] + a[3] + a[6] + a[8];\n\t\tt[1] = a[1] + a[4] + a[7] + a[11];\n\t\tt[2] = a[2] + a[3] + a[4] + a[5];\n\t\tt[3] = a[2] + a[6] + a[9] + a[12];\n\t\tt[4] = a[8] + a[9] + a[10] + a[11];\n\t\tt[5] = a[12] + a[10] + a[7] + a[5];\n\t\tfor(int i = 1; i < 6; ++i){\n\t\t\tif(t[i] != t[i-1])return ;\n\t\t}\n\t\tfor (int i = 1; i <= 12; i++) cout << a[i] << \" \";\n\t\treturn ;\n\t}\n\tfor(int i = 1;i < 13; ++i){\n\t\tif(!vis[i]){\n\t\t\tvis[i] = 1;\n\t\t\ta[x] = i;\n\t\t\tdfs(x+1);\n\t\t\tvis[i] = 0;\n\t\t}\n\t}\n}\nint main(){\n\tmemset(vis,0,sizeof(vis));\n\tcin >> a[1];\n\tvis[a[1]] = 1;\n\tcin >> a[2];\n\tvis[a[2]] = 1;\n\tcin >> a[3];\n\tvis[a[3]] = 1;\n\tdfs(1);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470159", + "status": 1, + "keywords": "图算法,算法高阶,图的表示,基本的图算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/56.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/57.json b/data_backup/cpp_code_json/57.json new file mode 100644 index 000000000..d1553a4f5 --- /dev/null +++ b/data_backup/cpp_code_json/57.json @@ -0,0 +1,18 @@ +{ + "question_id": 7461173, + "question_title": "n个素数的求和问题。", + "question_content": "

给定n(n≤100)个正整数,所有正整数均≤1000000;求其中所有素数的和。\n例如给定序列: 2 3 4 5 6,素数和为:10\n给定序列: 3 4 5 6 7, 素数和为:15\n给定序列: 12 19 23 35 68 71, 素数和为: 113\n输入格式:\n输入为两行。第一行是一个正整数n,表示有多少个数据。第二行是n个正整数组成的序列。\n输出格式:\n输出一个正整数,是上述序列中所有素数之和。

", + "difficulty": "简单", + "answer_id": 53446246, + "answer_content": "
\n#include <stdio.h>\nint isprime( int n);\nint main()\n{\n    int i,n,m,s=0;\n    scanf("%d", &n);\n    for( i=0; i<n; i++ ) {\n        scanf("%d", &m);\n        if(isprime(m)){\n            s+=m;\n        }\n    }\n    printf("%d", s);\n    return 0;\n}\nint isprime(int n)\n{\n    int i;\n    if(n<=1) return 0;\n    for(i=2;i*i<=n;i++)\n        if(n%i==0) return 0;\n    return 1;\n}\n
\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \nint isprime( int n);\nint main()\n{\n\tint i,n,m,s=0;\n\tscanf(\"%d\", &n);\n\tfor( i=0; i\nusing namespace std;\nint main()\n{\nint n;\ncin >> n;\nint ma, mi, a;\ncin >> a;\nmi = ma = a;\nfor (int i = 1; i < n; i++)\n{\ncin >> a;\nif (ma < a) ma = a;\nif (mi > a) mi = a;\n}\ncout << ma << endl << mi << endl;\n}\n```\n\n# 问题解决的话,请点下采纳", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint main()\n{\n\tint n;\n\tcin >> n;\n\tint ma, mi, a;\n\tcin >> a;\n\tmi = ma = a;\n\tfor (int i = 1; i < n; i++)\n\t{\n\t\tcin >> a;\n\t\tif (ma < a) ma = a;\n\t\tif (mi > a) mi = a;\n\t}\n\tcout << ma << endl << mi << endl;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470161", + "status": 1, + "keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/58.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/59.json b/data_backup/cpp_code_json/59.json new file mode 100644 index 000000000..fb653d5b9 --- /dev/null +++ b/data_backup/cpp_code_json/59.json @@ -0,0 +1,18 @@ +{ + "question_id": 251110, + "question_title": "筛选10到1000的回文数", + "question_content": "筛选出10到1000的回文数", + "difficulty": "简单", + "answer_id": 249084, + "answer_content": "\n\n```\n #include \nint main() \n{ \n int m,n,k; \n for(m=1;m<=1000;m++) \n { \n k=m; \n n=0; \n while(k>0) \n { \n n=n*10+(k%10); \n k=k/10; \n } \n if(m==n) printf(\"%d \", m); \n }\n return 0; \n}\n```\n\n", + "tag_name": "c++", + "cpp": "#include \nint main() \n{ \n\tint m,n,k; \n\tfor(m=1;m<=1000;m++) \n\t{ \n\t\tk=m; \n\t\tn=0; \n\t\twhile(k>0) \n\t\t{ \n\t\t\tn=n*10+(k%10); \n\t\t\tk=k/10; \n\t\t} \n\t\tif(m==n) printf(\"%d \", m); \n\t}\n\treturn 0;\t \n}", + "topic_link": "https://bbs.csdn.net/topics/600470162", + "status": 1, + "keywords": "回文,数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/59.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/6.json b/data_backup/cpp_code_json/6.json new file mode 100644 index 000000000..a6bb101e3 --- /dev/null +++ b/data_backup/cpp_code_json/6.json @@ -0,0 +1,18 @@ +{ + "question_id": 1089360, + "question_title": "输出1~10的平方与平方根", + "question_content": "![图片说明](https://img-ask.csdn.net/upload/202006/28/1593313257_732285.jpg)\n\n如图所示列出1~10,输出平方根和平方", + "difficulty": "简单", + "answer_id": 1295912, + "answer_content": "#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main()\n{\n\tdouble sum;\n\tdouble sq;\n\tfor(int i=1;i<=10;i++)\n\t{\n\t\tsum=i*i;\n\t\tsq=sqrt(i);\n\t\tprintf(\"%d %5.5f %12.2f\\n\",i,sq,sum);\n\t} \n\t\t \n}", + "tag_name": "c语言", + "cpp": "#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\nint main()\n{\n\tdouble sum;\n\tdouble sq;\n\tfor(int i=1;i<=10;i++)\n\t{\n\t\tsum=i*i;\n\t\tsq=sqrt(i);\n\t\tprintf(\"%d %5.5f %12.2f\\n\",i,sq,sum);\n\t} \n}", + "topic_link": "https://bbs.csdn.net/topics/600469843", + "status": 0, + "keywords": "数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/6.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/60.json b/data_backup/cpp_code_json/60.json new file mode 100644 index 000000000..308a9f876 --- /dev/null +++ b/data_backup/cpp_code_json/60.json @@ -0,0 +1,18 @@ +{ + "question_id": 7448649, + "question_title": "个位数是6,且能被3整除的五位数共有多少个?", + "question_content": "

要求:\n1、必须包含循环结构、顺序结构、选择分支结构。\n2、必须包含数组\n3、必须包含一个以上函数\n4、可以包含方针

", + "difficulty": "简单", + "answer_id": 53428800, + "answer_content": "
\n#include <iostream>\n\nusing namespace std;\nvoid search1(){\n    int i,t=0;\n    for(i=10000;i<=99999;i++){\n        if(i%3==0&&i%10==6)\n            t++;\n    }\n    cout<<t;\n}\nint main()\n{\n    search1();\n\n    return 0;\n}\n
\n\n

\"\" 

\n", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nvoid search1(){\n\tint i,t=0;\n\tfor(i=10000;i<=99999;i++){\n\t\tif(i%3==0&&i%10==6)\n\t\t\tt++;\n\t}\n\tcout<\nusing namespace std;\n\nvoid merge(int * a1, int m, int * a2, int n)\n{\n\tint m1 = m - 1;\n\tint n1 = n - 1;\n\tfor (int i = m + n - 1; i >= 0; i--)\n\t{\n\t\tif (m1 < 0) a1[i] = a2[n1--];\n\t\telse if (n1 < 0) a1[i] = a1[m1--];\n\t\telse if (a1[m1] < a2[n1]) a1[i] = a2[n1--];\n\t\telse a1[i] = a1[m1--];\n\t}\n}\n\nint main()\n{\n\tint m;\n\tint n;\n\tcin >> m;\n\tcin >> n;\n\tint a1[201];\n\tint a2[101];\n\tfor (int i = 0; i < m; i++) cin >> a1[i];\n\tfor (int i = 0; i < n; i++) cin >> a2[i];\n\tmerge(a1, m, a2, n);\n\tfor (int i = 0; i < m + n; i++) cout << a1[i] << \" \";\n\treturn 0;\n}\n```", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nvoid merge(int * a1, int m, int * a2, int n)\n{\n\tint m1 = m - 1;\n\tint n1 = n - 1;\n\tfor (int i = m + n - 1; i >= 0; i--)\n\t{\n\t\tif (m1 < 0) a1[i] = a2[n1--];\n\t\telse if (n1 < 0) a1[i] = a1[m1--];\n\t\telse if (a1[m1] < a2[n1]) a1[i] = a2[n1--];\n\t\telse a1[i] = a1[m1--];\n\t}\n}\nint main()\n{\n\tint m;\n\tint n;\n\tcin >> m;\n\tcin >> n;\n\tint a1[201];\n\tint a2[101];\n\tfor (int i = 0; i < m; i++) cin >> a1[i];\n\tfor (int i = 0; i < n; i++) cin >> a2[i];\n\tmerge(a1, m, a2, n);\n\tfor (int i = 0; i < m + n; i++) cout << a1[i] << \" \";\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470263", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/61.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/62.json b/data_backup/cpp_code_json/62.json new file mode 100644 index 000000000..099b948cc --- /dev/null +++ b/data_backup/cpp_code_json/62.json @@ -0,0 +1,18 @@ +{ + "question_id": 1053941, + "question_title": "猴子吃桃", + "question_content": "问题:猴子第一天摘了若干个桃子,吃了一半,不过瘾,又多吃了1个。第二天早上将剩余的桃子又吃掉一半,并且又多吃了1个。此后每天都是吃掉前一天剩下的一半零一个。到第n天再想吃时,发现只剩下1个桃子,问第一天它摘了多少桃子?为了加强交互性,由用户输入不同的天数n进行递推,即假设第n天的桃子数为1。同时还要增加对用户输入数据的合法性验证(如:不允许输入的天数是0和负数)\n", + "difficulty": "中等", + "answer_id": 1251130, + "answer_content": "\n```\n#include \n\nint main()\n{\n\tint ret,day,i=1,sum=1;\n\twhile (1)\n\t{\n\t\tprintf(\"Input days:\\n\");\n\t\tret=scanf(\"%d\",&day);\n\t\tif ((ret!=1)||(day<=0))\n\t\t{\n\t\t\tfflush(stdin);\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\tdo\n\t{\n\t\tsum=(sum+1)*2;\n\t\ti++;\n\t}while(i\nint main()\n{\n\tint ret,day,i=1,sum=1;\n\twhile (1)\n\t{\n\t\tprintf(\"Input days:\\n\");\n\t\tret=scanf(\"%d\",&day);\n\t\tif ((ret!=1)||(day<=0))\n\t\t{\n\t\t\tfflush(stdin);\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\tdo\n\t{\n\t\tsum=(sum+1)*2;\n\t\ti++;\n\t}while(i(1)标准体重=(身高-110)公斤;\n(2)超过标准体重5公斤为过胖;\n(3)低于标准体重5公斤为过瘦。\n例如:输入身高和体重分别为160,60,输出为过胖\n输入身高和体重分别为160,50,输出为标准\n输入身高和体重分别是160,40,输出为过瘦

", + "difficulty": "简单", + "answer_id": 53409166, + "answer_content": "

代码如下:

\n\n
\n#include <stdio.h>\n\n int main() \n { \n\t int h,w;\n\t printf("请输入身高(厘米)和体重(公斤)");\n\t scanf("%d %d",&h,&w);\n\n\tint s = h - 110;\n\tif( (w-s) > 5)\n\t\tprintf("过胖\\n");\n\telse if( s - w > 5)\n\t\tprintf("过瘦");\n\telse if(s - w == 0)\n\t\tprintf("标准\\n");\n\n\n\t //getchar();\n\t //getchar();\n\t return 0; \n } 
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint main() \n{ \n\tint h,w;\n\tprintf(\"请输入身高(厘米)和体重(公斤)\");\n\tscanf(\"%d %d\",&h,&w);\n\tint s = h - 110;\n\tif( (w-s) > 5)\n\t\tprintf(\"过胖\\n\");\n\telse if( s - w > 5)\n\t\tprintf(\"过瘦\");\n\telse\n\t\tprintf(\"标准\\n\");\n\treturn 0; \n} ", + "topic_link": "https://bbs.csdn.net/topics/600469850", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/63.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/64.json b/data_backup/cpp_code_json/64.json new file mode 100644 index 000000000..c31d12b9e --- /dev/null +++ b/data_backup/cpp_code_json/64.json @@ -0,0 +1,18 @@ +{ + "question_id": 7436200, + "question_title": "数组排序", + "question_content": "定义一个包含5个整型元素(1, 5, 3, 92, 6)的数组,将数组元素按照由 小到大的顺序输出", + "difficulty": "简单", + "answer_id": 53407715, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n\n#define N (int)5\n\nint main()\n{\n\tint a[N] = {1,5,3,92,6};\n\tint tmp;\n\tfor (int i = 0; i < N-1; i++)\n\t{\n\t\tfor (int j = 0;j < N-1-i;j++)\n\t\t{\n\t\t\tif (a[j] > a[j+1])\n\t\t\t{\n\t\t\t\ttmp = a[j];\n\t\t\t\ta[j] = a[j+1];\n\t\t\t\ta[j+1] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < N; i++)\n\t{\n\t\tprintf("%d ",a[i]);\n\t}\n\t//getchar();\n\t//getchar();\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#define N (int)5\nint main()\n{\n\tint a[N] = {1,5,3,92,6};\n\tint tmp;\n\tfor (int i = 0; i < N-1; i++)\n\t{\n\t\tfor (int j = 0;j < N-1-i;j++)\n\t\t{\n\t\t\tif (a[j] > a[j+1])\n\t\t\t{\n\t\t\t\ttmp = a[j];\n\t\t\t\ta[j] = a[j+1];\n\t\t\t\ta[j+1] = tmp;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int i = 0; i < N; i++)\n\t{\n\t\tprintf(\"%d \",a[i]);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470264", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/64.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/65.json b/data_backup/cpp_code_json/65.json new file mode 100644 index 000000000..1f1ba320b --- /dev/null +++ b/data_backup/cpp_code_json/65.json @@ -0,0 +1,18 @@ +{ + "question_id": 924952, + "question_title": "找出所有三位素数", + "question_content": "题目描述\n一个n位超级素数是指一个n位正整数,它的前1位,前2位,......,前n位均为素数,例如,733是个3位超级素数,因为7,73,733均为素数。输出全部的3位数超级素数。 \n输入\n输出\n全部的3位数超级素数,每行一个数", + "difficulty": "简单", + "answer_id": 1060112, + "answer_content": "\n```\n#include \n\nint isprime(int x)\n{\n if (x == 0 || x == 1) return 0;\n for (int i = 2; i <= x / 2; i++)\n if (!(x % i)) return 0;\n return 1;\n}\n\nint isallprime(int x)\n{\n\tdo\n {\n\t\tif (!isprime(x)) return 0;\n\t\tx /= 10;\n }\n\twhile (x > 0);\n return 1;\n}\n\nint main()\n{\n for (int i = 111; i < 999; i++)\n if (isallprime(i)) printf(\"%d\\n\", i);\n}\n```\n233\n239\n293\n311\n313\n317\n373\n379\n593\n599\n719\n733\n739\n797", + "tag_name": "c++", + "cpp": "#include \nint isprime(int x)\n{\n\tif (x == 0 || x == 1) return 0;\n\tfor (int i = 2; i <= x / 2; i++)\n\t\tif (!(x % i)) return 0;\n\treturn 1;\n}\nint isallprime(int x)\n{\n\tdo\n\t{\n\t\tif (!isprime(x)) return 0;\n\t\tx /= 10;\n\t}\n\twhile (x > 0);\n\treturn 1;\n}\nint main()\n{\n\tfor (int i = 111; i <= 1000; i++)\n\t\tif (isallprime(i)) printf(\"%d\\n\", i);\n}", + "topic_link": "https://bbs.csdn.net/topics/600469948", + "status": 1, + "keywords": "算法高阶,数论算法,素数的测试,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/65.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/66.json b/data_backup/cpp_code_json/66.json new file mode 100644 index 000000000..af9cd2da9 --- /dev/null +++ b/data_backup/cpp_code_json/66.json @@ -0,0 +1,18 @@ +{ + "question_id": 978676, + "question_title": "计算字符串逆序数", + "question_content": "例如:字符串中的内容为:a1Ab1D2,1\n#include \nusing namespace std;\n\nint solve(string s)\n{\n\tif (s.length() == 0) return 0;\n\tint n = 0;\n\tfor (int i = 1; i < s.length(); i++)\n\t\tif (s.c_str()[i] < s.c_str()[i - 1]) n++;\n\treturn n;\n}\n\nint main()\n{\n\tstring s = \"a1Ab1D2\";\n\tint n = solve(s);\n\tcout << n << endl;\n\treturn 0;\n}\n```\n\n# 问题解决请点下采纳", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint solve(string s)\n{\n\tif (s.length() == 0) return 0;\n\tint n = 0;\n\tfor (int i = 1; i < s.length(); i++)\n\t\tif (s.c_str()[i] < s.c_str()[i - 1]) n++;\n\treturn n;\n}\nint main()\n{\n\tstring s = \"a1Ab1D2\";\n\tint n = solve(s);\n\tcout << n << endl;\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469851", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/66.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/67.json b/data_backup/cpp_code_json/67.json new file mode 100644 index 000000000..ad7193e49 --- /dev/null +++ b/data_backup/cpp_code_json/67.json @@ -0,0 +1,17 @@ +{ + "question_id": 1058505, + "question_title": "报数", + "question_content": "有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。", + "difficulty": "简单", + "answer_id": 1255809, + "answer_content": "\n```\n#include\nint main()\n{ \n int i,n,a[100],count,* p,out;\n\n printf(\"共有几个人围成一圈?(不超过100人)\\n\");\n\n scanf(\"%d\",&n);\n\n for(i=0;i\nint main()\n{ \n int i,n,a[100],count,* p,out;\n printf(\"共有几个人围成一圈?(不超过100人)\\n\");\n scanf(\"%d\",&n);\n for(i=0;i\n\nint main()\n{\n\tint n;\n\tint cnt = 0;\n\tscanf(\"%d\", &n);\n\tfor (int a = 1; a < n; a++)\n\t\tfor (int b = a; b < n - a; b++)\n\t\t\tfor (int c = 1; c < n; c++)\n\t\t\t{\n\t\t\t\tif ((a+b)*(a+b)+c*c==n*n)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"a=%d b=%d c=%d\\n\", a, b, c);\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\tprintf(\"一共有%d种方案\", cnt);\n\treturn 0;\n}\n```\n5\na=1 b=2 c=4\na=1 b=3 c=3\na=2 b=2 c=3\n一共有3种方案Press any key to continue . . .\n\n\n10\na=1 b=5 c=8\na=1 b=7 c=6\na=2 b=4 c=8\na=2 b=6 c=6\na=3 b=3 c=8\na=3 b=5 c=6\na=4 b=4 c=6\n一共有7种方案Press any key to continue . . .\n\n", + "tag_name": "c++", + "cpp": "#include \nint main()\n{\n\tint n;\n\tint cnt = 0;\n\tscanf(\"%d\", &n);\n\tfor (int a = 1; a < n; a++)\n\t\tfor (int b = a; b < n - a; b++)\n\t\t\tfor (int c = 1; c < n; c++)\n\t\t\t{\n\t\t\t\tif ((a+b)*(a+b)+c*c==n*n)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"a=%d b=%d c=%d\\n\", a, b, c);\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\tprintf(\"一共有%d种方案\", cnt);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469852", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/68.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/69.json b/data_backup/cpp_code_json/69.json new file mode 100644 index 000000000..dc4f7a39d --- /dev/null +++ b/data_backup/cpp_code_json/69.json @@ -0,0 +1,18 @@ +{ + "question_id": 7449552, + "question_title": "按要求完成数据的输入输出", + "question_content": "

有6个学生,每个学生的数据包括学号、姓名、3门课的成绩、平均成绩,输入每个学生的信息,平均成绩需通过计算得出,输出学生的信息。要求:输入、输出不使用函数。

", + "difficulty": "简单", + "answer_id": 53429731, + "answer_content": "
\n#include<stdio.h>\n#include<string.h>\n#include<stdlib.h>\n int n;\nstruct person\n{\n    char id [20];\n    char name [20];\n    int s1,s2,s3;\n    int sum;\n    float ave;\n} p[100];\n\n\n\nint main()\n{\n    int i,j,t,m;\n    scanf("%d",&n);\n    for(int i=0; i<n; i++)\n    {\n        p[i].sum=0;\n        scanf("%s %s %d %d %d",p[i].id,p[i].name,&p[i].s1,&p[i].s2,&p[i].s3);\n        p[i].sum+=p[i].s1+p[i].s2+p[i].s3;\n        p[i].ave=p[i].sum/3.0;\n    }\n    for(i=0;i<n;i++)    {\n\n\t}\n    for(i=0; i<n; i++)\n    {\n        printf("%s %s %d %d %d %.2f\\n",p[i].id,p[i].name,p[i].s1,p[i].s2,p[i].s3,p[i].ave);\n}\n    }\n/* 6\n101 张三 80 76 98\n 102 李四 96 56 78\n 103 王五 64 89 63\n 104 小二 62 54 86\n 105 小四 78 86 91\n 106 小七 78 66 81*/\n
\n\n

\"\" 

\n", + "tag_name": "c语言", + "cpp": "#include\n#include\n#include\nint n;\nstruct person\n{\n\tchar id [20];\n\tchar name [20];\n\tint s1,s2,s3;\n\tint sum;\n\tfloat ave;\n} p[100];\nint main()\n{\n\tint i,j,t,m;\n\tscanf(\"%d\",&n);\n\tfor(int i=0; i给定公司N名员工的工龄,要求按工龄增序输出每个工龄段有多少员工。输入首先给出正整数N,即员工总人数;\n随后给出N个整数,即每个员工的工龄,范围在[0, 99]。其中,0-9为第1个工龄段,10-19为第2个工龄段,…,90-99为第10个工龄段。按工龄的递增顺序输出每个工龄的员工个数,格式为:“工龄:人数”。每项占一行。如果人数为0则不输出该项。

", + "difficulty": "简单", + "answer_id": 53429153, + "answer_content": "
\n#include<stdio.h>\nint main()\n{\n    int i,n,a[11]= {0},x;\n    scanf("%d",&n);\n    for(i=0; i<n; i++)\n    {\n        scanf("%d",&x);\n        if(x<=9)\n            a[1]++;\n        else if(x>9&&x<=19)\n            a[2]++;\n        else if(x>19&&x<=29)\n            a[3]++;\n        else if(x>29&&x<=39)\n            a[4]++;\n        else if(x>39&&x<=49)\n            a[5]++;\n        else if(x>49&&x<=59)\n            a[6]++;\n        else if(x>59&&x<=69)\n            a[7]++;\n        else if(x>69&&x<=79)\n            a[8]++;\n        else if(x>79&&x<=89)\n            a[9]++;\n        else\n            a[10]++;\n    }\n    for(i=1;i<=10;i++){\n        if(a[i]>0){\n            printf("%d-%d:%d\\n",i*10-10,i*10-1,a[i]);\n        }\n    }\n}\n
\n\n

\"\"

\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint i,n,a[11]= {0},x;\n\tscanf(\"%d\",&n);\n\tfor(i=0; i9&&x<=19)\n\t\t\ta[2]++;\n\t\telse if(x>19&&x<=29)\n\t\t\ta[3]++;\n\t\telse if(x>29&&x<=39)\n\t\t\ta[4]++;\n\t\telse if(x>39&&x<=49)\n\t\t\ta[5]++;\n\t\telse if(x>49&&x<=59)\n\t\t\ta[6]++;\n\t\telse if(x>59&&x<=69)\n\t\t\ta[7]++;\n\t\telse if(x>69&&x<=79)\n\t\t\ta[8]++;\n\t\telse if(x>79&&x<=89)\n\t\t\ta[9]++;\n\t\telse\n\t\t\ta[10]++;\n\t}\n\tfor(i=1;i<=10;i++){\n\t\tif(a[i]>0){\n\t\t\tprintf(\"%d-%d:%d\\n\",i*10-10,i*10-1,a[i]);\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470245", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/7.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/70.json b/data_backup/cpp_code_json/70.json new file mode 100644 index 000000000..62814d0bf --- /dev/null +++ b/data_backup/cpp_code_json/70.json @@ -0,0 +1,18 @@ +{ + "question_id": 7420132, + "question_title": "动态规划-硬币重量最轻问题", + "question_content": "

设有n种不同面值的硬币,第i种硬币的币值是Vi(其中V1=1),重量是Wi,i=1,2,...n且现在购买某种总币值为y的商品,需要用这些硬币付款,如果每种钱币使用的个数不限,那么如何选择付款的方法使得付出钱币的总重量最轻?使用动态规划设计策略设计一个求解该问题的算法。假设问题的输入实例是:

V1=1, V2=4, V3=6, V4=8

W1=1, W2=2,W3=4,W4=6

Y=12

要求输出优化函数表和标记函数表、以及硬币支付方式。

\n", + "difficulty": "困难", + "answer_id": 53378192, + "answer_content": "
\n#include<stdio.h>\nvoid strcpy(int *a, int *b, int Y){\n    for(int i=0;i<=Y;i++) *(a+i) = *(b+i);\n}\nvoid solve(){\n        int n; scanf("%d",&n);\n        int type[n], weight[n], Y, i, j, k;\n        for(i=0;i<n;i++) scanf("%d",&type[i]);\n        for(i=0;i<n;i++) scanf("%d",&weight[i]);\n        scanf("%d",&Y);\n        int Min[Y+1], Min_Path[Y+1], path[n][Y+1];\n        for(i=0;i<=Y;i++) Min[i] = 9999;\n        Min[0] = 0;\n        printf("\\n");\n        for(j=0;j<n;j++){\n            for(i=type[j]; i<=Y; i++)\n                if(Min[i] > Min[i-type[j]]+weight[j]){\n                    Min_Path[i] = type[j];\n                    Min[i] = Min[i-type[j]]+weight[j];\n                }\n            for(k=1;k<=Y;k++) printf("%-3d",Min[k]);\n            printf("\\n");\n            strcpy(path[j],Min_Path,Y);\n        }\n\n        printf("\\n");\n        for(i=0;i<n;i++){\n            for(j=1;j<=Y;j++)\n                printf("%-3d",path[i][j]);\n            printf("\\n");\n        }\n\n        int y=Y;\n        printf("\\n支付方式:");\n        while (y){\n            printf("%d ",Min_Path[y]);\n            y -= Min_Path[y];\n        }\n        printf("\\n总重量:%d\\n",Min[Y]);\n}\nint main(){\n    solve();\n    return 1;\n}\n/*\n4\n1 4 6 8\n1 3 2 6\n12\n */
\n\n

\"\"

\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\nvoid strcpy(int *a, int *b, int Y){\n\tfor(int i=0;i<=Y;i++) *(a+i) = *(b+i);\n}\nvoid solve(){\n\tint n; scanf(\"%d\",&n);\n\tint type[n], weight[n], Y, i, j, k;\n\tfor(i=0;i Min[i-type[j]]+weight[j]){\n\t\t\t\tMin_Path[i] = type[j];\n\t\t\t\tMin[i] = Min[i-type[j]]+weight[j];\n\t\t\t}\n\t\tfor(k=1;k<=Y;k++) printf(\"%-3d\",Min[k]);\n\t\tprintf(\"\\n\");\n\t\tstrcpy(path[j],Min_Path,Y);\n\t}\n\tprintf(\"\\n\");\n\tfor(i=0;i从键盘输入一个正整数存入变量n中,再输入n个整数,然后找出所有小于平均值的数,并按输入顺序输出。\n \n 

", + "difficulty": "简单", + "answer_id": 53441440, + "answer_content": "
\n#include<stdio.h>\n\nint main()\n{\n\tint i,n,x,sum=0,a[100];\n\tfloat ave;\n\tscanf("%d",&n);\n\tfor(i=0;i<n;i++){\n        scanf("%d",&a[i]);\n        sum+=a[i];\n\t}\n\tave=sum*1.0/n;\n\tfor(i=0;i<n;i++){\n        if(a[i]<ave)\n            printf("%d",a[i]);\n\t}\n\n\treturn 0;\n\n}\n
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include\nint main()\n{\n\tint i,n,sum=0,a[100];\n\tfloat ave;\n\tscanf(\"%d\",&n);\n\tfor(i=0;i要求:模仿现实生活中的挂历。\n当前页以系统当前日期的月份为准显示当前月的每一天(显示出日及对应的星期几)。\n当系统日期变到下一月时,系统自动翻页到下一月。\n 

", + "difficulty": "简单", + "answer_id": 53445491, + "answer_content": "

到底要C版本,还是C++版本啊

\n\n
\n#include <stdio.h>\n \nint year(int y)\n{\n\tif ((y%4==0) && (y%100!=0) || y%400==0)\n\t\treturn 366;\n\telse\n\t\treturn 365;\n}\n \nint main()\n{\n\tint y;\n\tint i,j,sum=0;\t\n\tint begin,week;\n\tint days[12]={31,28,31,30,31,30,31,31,30,31,30,31};\n \n\tscanf("%d",&y);\n\tfor(i=1;i<y;i++)\n\t\tsum+=year(i);\n\t\n\tweek=(sum+1)%7;\t\t//表示该年1月1日为星期几\n\t\n\tif(year(y)==366)\n\t\tdays[1]=29;\t\n \n\tprintf("\\n%d年日历如下:\\n\\n",y);\n \n\tfor(i=0;i<12;i++)\n\t{\n\t\tprintf("       %d月          \\n",i+1);\n\t\tprintf("  7  1  2  3  4  5  6\\n");\n\t\tprintf("=====================\\n");\n\t\tbegin=1;\n\t\tfor(j=0;j<week;j++)\n\t\t\tprintf("   ");\n\t\twhile(begin<=days[i])\n\t\t{\n\t\t\tprintf("%3d",begin);\n\t\t\tbegin++;\n\t\t\tweek=(week+1)%7;\n\t\t\tif(week%7==0)\n\t\t\t\tprintf("\\n");\n\t\t}\n\t\tprintf("\\n\\n");\n \n\t}\n\t\n\t\n \n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint year(int y)\n{\n\tif ((y%4==0) && (y%100!=0) || y%400==0)\n\t\treturn 366;\n\telse\n\t\treturn 365;\n}\nint main()\n{\n\tint y;\n\tint i,j,sum=0;\t\n\tint begin,week;\n\tint days[12]={31,28,31,30,31,30,31,31,30,31,30,31};\n\tscanf(\"%d\",&y);\n\tfor(i=1;i对于一个字符串,如果这个字符串在ASCII码的意义上是有序的,即升序或降序,则称该字符串为“优雅的字符串”。一个长为n的字符串s,对于1<= i <= n - 1,如果总有s[i] <= s[i+1],则字符串为升序;如果总有s[i] >= s[i+1],则字符串降序。现给定一个字符串,请你判断该字符串是否“优雅”,如果该字符串是“优雅”的,则判断是“正优雅”(升序)还是“负优雅”(降序)。\n输入描述\n一个非空,不包含空格的字符串s,保证字符串中的字符都是ASCII标准中的字符。数据保证不会出现所有字符相同的字符串。(2<= length(s) <=1e5)\n输出描述\n如果字符串“正优雅”,则输出“Positive elegance”,如果“负优雅”,则输出“Negative elegance”,否则输出“Non elegance”(均不含引号)。\n样例输入 (*+12356ASdfz\n样例输出\nPositive elegance

", + "difficulty": "困难", + "answer_id": 53438399, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdio.h>\n#include <string.h>\n\nint main()\n{\n\tchar a[100] = {0};\n\tint i;\n\tint zyy = 1;\n\tint fyy = 1;\n\tprintf("请输入字符串:");\n\tgets(a);\n\t//判断是否正优雅\n\tfor (i=1;i<strlen(a);i++)\n\t{\n\t\tif(a[i] < a[i-1])\n\t\t{\n\t\t\tzyy = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n\t//判断是否负优雅\n\tfor (i=1;i<strlen(a);i++)\n\t{\n\t\tif(a[i] > a[i-1])\n\t\t{\n\t\t\tfyy = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (zyy && !fyy)\n\t{\n\t\tprintf("Positive elegance\\n");\n\t}else if (!zyy && fyy)\n\t{\n\t\tprintf("Negative elegance\\n");\n\t}else\n\t\tprintf("Non elegance\\n");\n\treturn 0;\n\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tchar a[100] = {0};\n\tint i;\n\tint zyy = 1;\n\tint fyy = 1;\n\tprintf(\"请输入字符串:\");\n\tgets(a);\n\tfor (i=1;i a[i-1])\n\t\t{\n\t\t\tfyy = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (zyy && !fyy)\n\t{\n\t\tprintf(\"Positive elegance\\n\");\n\t}else if (!zyy && fyy)\n\t{\n\t\tprintf(\"Negative elegance\\n\");\n\t}else\n\t\tprintf(\"Non elegance\\n\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470165", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/73.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/74.json b/data_backup/cpp_code_json/74.json new file mode 100644 index 000000000..70722ebed --- /dev/null +++ b/data_backup/cpp_code_json/74.json @@ -0,0 +1,18 @@ +{ + "question_id": 1057668, + "question_title": "计算sin(x)", + "question_content": "\n描述\n计算sin(x)=x-x^3/3!+x^5/5!-X^7/7!+......,直到最后一项的绝对值小于10-7时停止计算。其中-2Π<=x<=2Π,^表示次方,如x^3表示x的3次方。\n输入\n一个实数x,-2Π<=x<=2Π\n输出\nsin(x)的值\n输入样例 1 \n3.142\n输出样例 1\n-0.000407347", + "difficulty": "中等", + "answer_id": 1254771, + "answer_content": "\n```\n#include\n#include\n\ndouble sin(double);\ndouble nResult(double,double);\n\nint main()\n{\n double x=0;\n scanf(\"%lf\",&x);\n printf(\"sin(%lf)=%lf\\n\",x,sin(x));\n return 0;\n}\n\ndouble sin(double x)\n{\n //sin(x)=x-x^3/3!+x^5/5!-x^7/7!+……+(-1)(n^2n+1)/(2n+1)!+……\n int i=0;\n double result=0,n=0;\n while( fabs( n=nResult(x,2*++i-1) ) > 0e-7 )//绝对值大于10^-7次方就循环\n result+=(i%2==1)?n:-n;\n return result;\n}\n\ndouble nResult(double x,double n)\n{\n //(n^2n+1)/(2n+1)!也就是n/1*n/2*n/3*n/4*.....n/(2n+1)\n return n==1?x:nResult(x,n-1)*x/n;\n}\n```", + "tag_name": "c++", + "cpp": "#include\n#include\ndouble sin(double);\ndouble nResult(double,double);\nint main()\n{\n\tdouble x=0;\n\tscanf(\"%lf\",&x);\n\tprintf(\"sin(%lf)=%lf\\n\",x,sin(x));\n\treturn 0;\n}\ndouble sin(double x)\n{\n\tint i=0;\n\tdouble result=0,n=0;\n\twhile( fabs( n=nResult(x,2*++i-1) ) > 0e-7 )\n\t\tresult+=(i%2==1)?n:-n;\n\treturn result;\n}\ndouble nResult(double x,double n)\n{\n\treturn n==1?x:nResult(x,n-1)*x/n;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470166", + "status": 1, + "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/74.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/75.json b/data_backup/cpp_code_json/75.json new file mode 100644 index 000000000..ffb022c69 --- /dev/null +++ b/data_backup/cpp_code_json/75.json @@ -0,0 +1,18 @@ +{ + "question_id": 1059365, + "question_title": "不喜欢带钱的小C", + "question_content": "题目描述:\n小C不喜欢带钱,有一次竟被他碰上了一家不能使用移动支付(也不能找钱)的神秘商店。请问小C至少准备多少张RMB才能恰好支付n元。RMB的面额有100元,50元,20元,10元,5元,1元。\n输入格式:\n输入一个整数n\n输出格式:\n最少带几张。\n样例输入1:\n50\n样例输出1:\n1\n约定:\n1<=n<=100", + "difficulty": "中等", + "answer_id": 1256674, + "answer_content": "\n```\n#include \n\nusing namespace std;\n\nint solve(int tar, int * meta, int metan, int * seed = NULL, int seedn = 0)\n{\n\tif (tar == 0)\n\t{\n\t\t//for (int i = 0; i < seedn; i++) cout << seed[i] << \" \";\n\t\t//cout << endl;\n\t\treturn seedn;\n\t}\n\tint min = -1;\n\tint m;\n\tint * seed1 = new int[seedn + 1];\n\tif (seed)\n\t\tmemcpy(seed1, seed, sizeof(int) * seedn);\n\tfor (int i = 0; i < metan; i++)\n\t{\n\t\tif (meta[i] <= tar)\n\t\t{\n\t\t\tseed1[seedn] = meta[i];\n\t\t\tm = solve(tar - meta[i], meta, metan, seed1, seedn + 1);\n\t\t\tif (m != -1 && (min == -1 || min > m))\n\t\t\t\tmin = m;\n\t\t\tbreak;\n\t\t}\n\t}\n\tdelete[] seed1;\n\treturn min;\n}\n\nint main()\n{\n\tint arr[] = { 100, 50, 20, 10, 5, 1 };\n\tint n = 6;\n\tint total;\n\tcin >> total;\n\tint result = solve(total, arr, n);\n\tcout << result << endl;\n\treturn 0;\n}\n\n```\n# 问题解决的话,请点下`采纳`", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nint solve(int tar, int * meta, int metan, int * seed = NULL, int seedn = 0)\n{\n\tif (tar == 0)\n\t{\n\t\treturn seedn;\n\t}\n\tint min = -1;\n\tint m;\n\tint * seed1 = new int[seedn + 1];\n\tif (seed)\n\t\tmemcpy(seed1, seed, sizeof(int) * seedn);\n\tfor (int i = 0; i < metan; i++)\n\t{\n\t\tif (meta[i] <= tar)\n\t\t{\n\t\t\tseed1[seedn] = meta[i];\n\t\t\tm = solve(tar - meta[i], meta, metan, seed1, seedn + 1);\n\t\t\tif (m != -1 && (min == -1 || min > m))\n\t\t\t\tmin = m;\n\t\t\tbreak;\n\t\t}\n\t}\n\tdelete[] seed1;\n\treturn min;\n}\nint main()\n{\n\tint arr[] = { 100, 50, 20, 10, 5, 1 };\n\tint n = 6;\n\tint total;\n\tcin >> total;\n\tint result = solve(total, arr, n);\n\tcout << result << endl;\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469951", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/75.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/76.json b/data_backup/cpp_code_json/76.json new file mode 100644 index 000000000..b96a2c5e0 --- /dev/null +++ b/data_backup/cpp_code_json/76.json @@ -0,0 +1,18 @@ +{ + "question_id": 995800, + "question_title": "Sine的奇怪朋友", + "question_content": "题目描述\nSine 的一个朋友疯了,最近他老爱说反话,别人说什么他就倒着说一遍,真是个奇怪的人。那他到底说了什么呢?\n(他说的话不超过 1000 个字符。)\n输入描述\n输入一个正整数 n,表示说话的次数。下面 n 行表示说的话\n输出描述\n占 n 行,每行表示对应输入的反话\n样例输入\n2\ni am speaking\nACMer\n样例输出\ngnikaeps ma i\n", + "difficulty": "中等", + "answer_id": 1169072, + "answer_content": "\n```\n#include\n#include\n#define N 1000\nint main()\n{\n int i,m,n;\n char st1[N];\n char st2[N];\n memset(st1,0x0,N);\n memset(st1,0x0,N);\n scanf(\"%d\",&m);\n getchar();\n while(m--)\n {\n gets(st1);\n i = strlen(st1);\n for (n=0;i>0;)\n st2[n++] = st1[--i];\n st2[n] = '\\0';\n printf(\"%s\\n\",st2);\n }\n return 0;\n}\n\n```", + "tag_name": "c语言", + "cpp": "#include\n#include\n#define N 1000\nint main()\n{\n\tint i,m,n;\n\tchar st1[N];\n\tchar st2[N];\n\tmemset(st1,0x0,N);\n\tscanf(\"%d\",&m);\n\tgetchar();\n\twhile(m--)\n\t{\n\t\tgets(st1);\n\t\ti = strlen(st1);\n\t\tfor (n=0;i>0;)\n\t\t\tst2[n++] = st1[--i];\n\t\tst2[n] = '\\0';\n\t\tprintf(\"%s\\n\",st2);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470265", + "status": 0, + "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/76.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/77.json b/data_backup/cpp_code_json/77.json new file mode 100644 index 000000000..93be52ba5 --- /dev/null +++ b/data_backup/cpp_code_json/77.json @@ -0,0 +1,18 @@ +{ + "question_id": 7456837, + "question_title": "按要求求质数", + "question_content": "求10-100之间个位数为7的质数", + "difficulty": "简单", + "answer_id": 53440905, + "answer_content": "
\n#include <stdio.h>\nint isp(int n)\n{\n    int i;\n    if (n<2)\n        return 0;\n    for (i=2;i*i<=n;++i)\n    {\n        if (n%i==0)\n            return 0;\n    }\n    return 1;\n}\nint main()\n{\n    int i=17;\n    while (i<=100)\n    {\n        if (isp(i))\n            printf("%d  ",i);\n        i+=10;   //只需要验证17,27,37,47,57,67,77,87,97这9个数\n    }\n    printf("\\n");  \n    return 0;\n}
\n\n

\"\" 

\n", + "tag_name": "c语言", + "cpp": "#include \nint isp(int n)\n{\n\tint i;\n\tif (n<2)\n\t\treturn 0;\n\tfor (i=2;i*i<=n;++i)\n\t{\n\t\tif (n%i==0)\n\t\t\treturn 0;\n\t}\n\treturn 1;\n}\nint main()\n{\n\tint i=17;\n\twhile (i<=100)\n\t{\n\t\tif (isp(i))\n\t\t\tprintf(\"%d \",i);\n\t\ti+=10; \n\t}\n\tprintf(\"\\n\"); \n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470167", + "status": 1, + "keywords": "质数,数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/77.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/78.json b/data_backup/cpp_code_json/78.json new file mode 100644 index 000000000..8b197e9da --- /dev/null +++ b/data_backup/cpp_code_json/78.json @@ -0,0 +1,18 @@ +{ + "question_id": 1057453, + "question_title": "输入一个正整数n(代表图形的行数),输出如样例形式的图形", + "question_content": "输入:5\n输出:\n A\n ABA \n ABCBA \n ABCDCBA \n ABCDEDCBA", + "difficulty": "中等", + "answer_id": 1254581, + "answer_content": "\n```\n#include \n#include \n\nusing namespace std;\n\nint main() {\n\tint N;\n\tcin >> N;\n\tfor (int i = 0; i < N; i++)\n\t{\n\t\tfor (int j = 0; j < N - i; j++) printf(\" \");\n\t\tfor (int j = 0; j < i; j++) printf(\"%c\", (char)(j + 'A'));\n\t\tfor (int j = i; j >= 0; j--) printf(\"%c\", (char)(j + 'A'));\n\t\tprintf(\"\\n\");\n\t}\n\treturn 0;\n}\n\n```\n# 问题解决的话,请点下采纳", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint main() {\n\tint N;\n\tcin >> N;\n\tfor (int i = 0; i < N; i++)\n\t{\n\t\tfor (int j = 0; j < N - i; j++) printf(\" \");\n\t\tfor (int j = 0; j < i; j++) printf(\"%c\", (char)(j + 'A'));\n\t\tfor (int j = i; j >= 0; j--) printf(\"%c\", (char)(j + 'A'));\n\t\tprintf(\"\\n\");\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470266", + "status": 1, + "keywords": "数学运算,图形输出", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/78.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/79.json b/data_backup/cpp_code_json/79.json new file mode 100644 index 000000000..9f91f2cc0 --- /dev/null +++ b/data_backup/cpp_code_json/79.json @@ -0,0 +1,18 @@ +{ + "question_id": 227612, + "question_title": "用递归实现任意的正整数按反序输出", + "question_content": "编写一个递归函数,将任意的正整数按反序输出。例如,输入\"12345\"输出\"54321\"", + "difficulty": "简单", + "answer_id": 192049, + "answer_content": "\n\n```\n #include \nusing namespace std;\n\nvoid revert(int n)\n{\n if ( n>= 0 && n<= 9 )\n {\n cout<\nusing namespace std;\nvoid revert(int n)\n{\n\tif ( n>= 0 && n<= 9 )\n\t{\n\t\tcout<\n#include <stdio.h>\nint main(){\n int n;\n while (scanf("%d",&n)!=EOF) {\n int t=0,sum=0,a[1000];\n for(int i=0; i<n; i++) {\n scanf("%d",&a[i]);\n }\n for(int i=1; i<n; i++) {\n if(a[i-1]<a[i]) {\n t++;\n if(sum<t)\n sum=t; //将最大的t赋值给sum \n } else\n t=0;\n }\n if(sum==0) {\n sum=0;\n } else sum=sum+1;\n printf("%d\\n",sum);\n }\n return 0;\n}\n\n

 

", + "tag_name": "c++", + "cpp": "#include \nint main(){\n\tint n;\n\twhile (scanf(\"%d\",&n)!=EOF) {\n\t\tint t=0,sum=0,a[1000];\n\t\tfor(int i=0; i\n\nint main()\n{\n\tint min = (1 << 31) - 1;\n\tint idx = 0;\n\tint arr[] = {915,941,960,976,992,1015,1034,1050,1073,1089,1115,1131,1150,1166,1182,1208,1227};\n\tint n = 1000;\n\tfor (int i = 0; i < sizeof(arr) / sizeof(int); i++)\n\t{\n\t\tint diff = arr[i] - n;\n\t\tif (diff < 0) diff = -diff;\n\t\tif (diff < min)\n\t\t{\n\t\t\tmin = diff;\n\t\t\tidx = i;\n\t\t}\n\t}\n\tprintf(\"最接近的是%d 下标是%d\", arr[idx], idx);\n \treturn 0;\n}\n```\n最接近的是992 下标是4\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint min = (1 << 31) - 1;\n\tint idx = 0;\n\tint arr[] = {915,941,960,976,992,1015,1034,1050,1073,1089,1115,1131,1150,1166,1182,1208,1227};\n\tint n = 1000;\n\tfor (int i = 0; i < sizeof(arr) / sizeof(int); i++)\n\t{\n\t\tint diff = arr[i] - n;\n\t\tif (diff < 0) diff = -diff;\n\t\tif (diff < min)\n\t\t{\n\t\t\tmin = diff;\n\t\t\tidx = i;\n\t\t}\n\t}\n\tprintf(\"最接近的是%d 下标是%d\", arr[idx], idx);\n \treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470168", + "status": 1, + "keywords": "算法高阶,数论算法,元素的幂,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/80.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/81.json b/data_backup/cpp_code_json/81.json new file mode 100644 index 000000000..31baeb11c --- /dev/null +++ b/data_backup/cpp_code_json/81.json @@ -0,0 +1,18 @@ +{ + "question_id": 7433864, + "question_title": "移动数组中的字符", + "question_content": "在数组中有n个字符,使前面各字符顺序向后移动m个位置,并使最后m个字符变成最前面的 m 个字符", + "difficulty": "中等", + "answer_id": 53404201, + "answer_content": "

代码如下,如有帮助,请采纳一下,谢谢。

\n\n
\n#include <iostream>\nusing namespace std;\nvoid funShift(int m,char *p,int n)\n{\n\tchar c;\n\tfor (int j = 0; j < m;j++)\n\t{\n\t\tc = p[n-1];\n\t\tfor (int i = n-1;  i > 0; i--)\n\t\t{\n\t\t\tp[i] = p[i-1];\n\t\t}\n\t\tp[0] = c;\n\t}\n\t\n}\nint main() \n{ \n\tint i,m,n; \n\tcin >> m >> n; \n\tchar *p =new char[n+1];\n\tp[n] = 0;\n\tfor(i = 0; i < n; ++i) \n\t\tcin >> p[i]; \n\tfunShift(m,p,n); \n\tfor(i = 0; i < n; ++i) \n\t\tcout << p[i] << ' '; \n\tcout << endl; \n\tdelete [] p; \n\n\tgetchar();\n\tgetchar();\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \nusing namespace std;\nvoid funShift(int m,char *p,int n)\n{\n\tchar c;\n\tfor (int j = 0; j < m;j++)\n\t{\n\t\tc = p[n-1];\n\t\tfor (int i = n-1; i > 0; i--)\n\t\t{\n\t\t\tp[i] = p[i-1];\n\t\t}\n\t\tp[0] = c;\n\t}\n}\nint main() \n{ \n\tint i,m,n; \n\tcin >> m >> n; \n\tchar *p =new char[n+1];\n\tp[n] = 0;\n\tfor(i = 0; i < n; ++i) \n\t\tcin >> p[i]; \n\tfunShift(m,p,n); \n\tfor(i = 0; i < n; ++i) \n\t\tcout << p[i] << ' '; \n\tcout << endl; \n\tdelete [] p; \n\tgetchar();\n\tgetchar();\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470169", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/81.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/82.json b/data_backup/cpp_code_json/82.json new file mode 100644 index 000000000..bc9f12162 --- /dev/null +++ b/data_backup/cpp_code_json/82.json @@ -0,0 +1,18 @@ +{ + "question_id": 7434242, + "question_title": "计算出现次数最多的整数及其出现次数", + "question_content": "

【问题描述】\n输入一组无序的整数,编程输出其中出现次数最多的整数及其出现次数。\n【输入形式】\n先从标准输入读入整数的个数(大于等于1,小于等于100),然后在下一行输入这些整数,各整数之间以一个空格分隔。\n【输出形式】\n在标准输出上输出出现次数最多的整数及其出现次数,两者以一个空格分隔;若出现次数最多的整数有多个,则按照整数升序分行输出。\n【样例输入】\n10\n0 -50 0 632 5813 -50 9 -50 0 632\n【样例输出】\n-50 3\n0 3\n【样例说明】\n输入了10个整数,其中出现次数最多的是-50和0,都是出现3次。

", + "difficulty": "困难", + "answer_id": 53404633, + "answer_content": "
\n#include <stdio.h>\n\nint main()\n\n{\n\n    int a[50],b[50],c[50],n,i,j,t,max;\n\n    scanf("%d",&n);\n\n    for(i=0;i<n;i++)\n\n       {\n\n        scanf("%d",&a[i]);\n\n       }\n\n    for(i=1;i<n;i++)\n\n        for(j=0;j<n-1;j++)\n\n        {\n\n          if(a[j]>a[j+1])\n\n          {\n\n              t=a[j];\n\n              a[j]=a[j+1];\n\n              a[j+1]=t;\n\n          }\n\n        }\n\n        j=0;\n\n        t=-1;\n\n    for(i=0;i<n-1;i++)\n\n        {\n\n            if(a[i]!=a[i+1])\n\n            {\n\n                b[j]=i-t;\n\n                c[j]=i;\n\n                t=i;\n\n                j++;\n\n            }\n\n        }\n\n           b[j]=n-1-t;\n\n           c[j]=n-1;\n\n        max=b[0];\n\n    for(i=1;i<=j;i++)\n\n    {\n\n        if(max<b[i])\n\n            {\n\n                max=b[i];\n\n            }\n\n    }\n\n    for(i=0;i<=j;i++)\n\n        if(b[i]==max)\n\n    {\n\n        t=c[i];\n\n        printf("%d %d\\n",a[t],b[i]);\n\n    }\n\n    return 0;\n\n}\n
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint a[50],b[50],c[50],n,i,j,t,max;\n\tscanf(\"%d\",&n);\n\tfor(i=0;ia[j+1])\n\t\t {\n\t\t\t t=a[j];\n\t\t\t a[j]=a[j+1];\n\t\t\t a[j+1]=t;\n\t\t }\n\t\t}\n\t\tj=0;\n\t\tt=-1;\n\tfor(i=0;i \n#include\nint main(){\n\tint n;\n\tscanf(\"%d\",&n);\n\t\n\tint i;\n\tdouble a1 = 2, b1 = 1;\n\tdouble a2 = 3, b2 = 2;\n\tdouble sum = a1/b1 - a2/b2;\n\t\n\tif(n==1) printf(\"%f\\n\",a1/b1);\n\telse if (n==2) printf(\"%f\\n\",sum);\n\telse{\n\t\tfor(i = 0;i \n#include\nint main(){\n\tint n;\n\tscanf(\"%d\",&n);\n\tint i;\n\tdouble a1 = 2, b1 = 1;\n\tdouble a2 = 3, b2 = 2;\n\tdouble sum = a1/b1 - a2/b2;\n\tif(n==1) printf(\"%f\\n\",a1/b1);\n\telse if (n==2) printf(\"%f\\n\",sum);\n\telse{\n\t\tfor(i = 0;i 给你一个整数数组 arr 。请你将数组中的元素按照其二进制表示中,数字 1 的数目升序排序。 如果存在多个数字二进制中 1 的数目相同,则必须将它们按照数值大小升序排列。请你返回排序后的数组。

", + "difficulty": "简单", + "answer_id": 1318491, + "answer_content": "
\n#include<stdio.h>\n#include<stdlib.h>\nint oneNum(int x)\n{\n    int cnt = 0;\n    while(x)\n    {\n        cnt++;\n        x = x&(x-1);\n    }\n    return cnt;\n}\n\nint cmp(const void *a,const void*b)\n{\n    int al,bl;\n    int ret;\n    al = *(int*)a;\n    bl = *(int*)b;\n    ret =  oneNum(al) - oneNum(bl);\n    return  ret ? ret : al - bl;\n}\n\nint main()\n{\n    int s[]={1,2,3,5,6,7,8},i;\n    int len = sizeof(s)/sizeof(*s);\n    qsort(s,len,4,cmp);\n    for(i = 0 ; i < len ; i++)\n    {\n        printf(\"%d\\n\",s[i]);\n    }\n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\n#include\nint oneNum(int x)\n{\n\tint cnt = 0;\n\twhile(x)\n\t{\n\t\tcnt++;\n\t\tx = x&(x-1);\n\t}\n\treturn cnt;\n}\nint cmp(const void *a,const void*b)\n{\n\tint al,bl;\n\tint ret;\n\tal = *(int*)a;\n\tbl = *(int*)b;\n\tret = oneNum(al) - oneNum(bl);\n\treturn ret ? ret : al - bl;\n}\nint main()\n{\n\tint s[]={1,2,3,5,6,7,8},i;\n\tint len = sizeof(s)/sizeof(*s);\n\tqsort(s,len,4,cmp);\n\tfor(i = 0 ; i < len ; i++)\n\t{\n\t\tprintf(\"%d\\n\",s[i]);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469952", + "status": 1, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/84.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/85.json b/data_backup/cpp_code_json/85.json new file mode 100644 index 000000000..aeb50d1cb --- /dev/null +++ b/data_backup/cpp_code_json/85.json @@ -0,0 +1,18 @@ +{ + "question_id": 7446208, + "question_title": "求数列第n项值", + "question_content": "

求数列第n项值:1,2,3,6,11,20,37,68,125,230,.....例如:第7项为37,第9项为125。

", + "difficulty": "简单", + "answer_id": 53425424, + "answer_content": "
\n#include <stdio.h>\n\nint main(void) { \n    int n;\n    printf("请输入n的值:");\n    scanf("%d",&n);\n    if(n==1){\n        printf("第1项为1\\n");\n    }else if(n==2){\n        printf("第2项为2\\n");\n    }else if(n==3){\n        printf("第3项为3\\n");\n    }else{\n        int f1=1,f2=2,f3=3;\n        int i,fn;\n        for(i=4;i<=n;i++){\n            fn=f1+f2+f3;\n            f1=f2;\n            f2=f3;\n            f3=fn;\n        }\n        printf("第%d项为%d\\n",n,fn);\n    }\n    return 0;\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \nint main(void) { \n\tint n;\n\tprintf(\"请输入n的值:\");\n\tscanf(\"%d\",&n);\n\tif(n==1){\n\t\tprintf(\"第1项为1\\n\");\n\t}else if(n==2){\n\t\tprintf(\"第2项为2\\n\");\n\t}else if(n==3){\n\t\tprintf(\"第3项为3\\n\");\n\t}else{\n\t\tint f1=1,f2=2,f3=3;\n\t\tint i,fn;\n\t\tfor(i=4;i<=n;i++){\n\t\t\tfn=f1+f2+f3;\n\t\t\tf1=f2;\n\t\t\tf2=f3;\n\t\t\tf3=fn;\n\t\t}\n\t\tprintf(\"第%d项为%d\\n\",n,fn);\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469855", + "status": 1, + "keywords": "数列,数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/85.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/86.json b/data_backup/cpp_code_json/86.json new file mode 100644 index 000000000..9b4ea46fe --- /dev/null +++ b/data_backup/cpp_code_json/86.json @@ -0,0 +1,18 @@ +{ + "question_id": 237871, + "question_title": "从指定位置插入字符串", + "question_content": "编写程序,输入字符串S1和S2以及插入位置n,在字符串S1中的指定位置n处插入字符串S2。例如,输入“jiangsu”、“123”和位置3,则输出“ji123angsu”。", + "difficulty": "简单", + "answer_id": 219299, + "answer_content": "\n\n```\n #include \n#include \nusing namespace std;\n\nint main()\n{\n\tstring str1;\n\tstring str2;\n\tint pos;\n\tdo\n\t{\n\t\tif ((cin >> str1 >> str2 >> pos) && (pos >= 1))\n\t\t{\n\t\t\tstr1.insert(pos - 1, str2);\n\t\t\tcout << str1 << endl;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcout << \"Invalid Input\" << endl;\n\t\t\tbreak;\n\t\t}\n\t\t\n\t} while (false);\n return 0;\n}\n```\n\n", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint main()\n{\n\tstring str1;\n\tstring str2;\n\tint pos;\n\tdo\n\t{\n\t\tif ((cin >> str1 >> str2 >> pos) && (pos >= 1))\n\t\t{\n\t\t\tstr1.insert(pos - 1, str2);\n\t\t\tcout << str1 << endl;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcout << \"Invalid Input\" << endl;\n\t\t\tbreak;\n\t\t}\n\t} while (false);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469953", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/86.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/87.json b/data_backup/cpp_code_json/87.json new file mode 100644 index 000000000..b9ff44419 --- /dev/null +++ b/data_backup/cpp_code_json/87.json @@ -0,0 +1,18 @@ +{ + "question_id": 237824, + "question_title": "统计某一单科成绩各分数段的分布人数", + "question_content": "设某班有若干人,写一程序统计某一单科成绩各分数段的分布人数,每人的成绩随机输入,输入负数表示输入结束。要求按下面的格式输出统计结果(“**”表示实际分布人数)\n0~39\t**\n40~49\t**\n50~59\t**\n……\n90~100\t**", + "difficulty": "简单", + "answer_id": 218762, + "answer_content": "这是上课题目?\n```\n #include \n#include \nusing namespace std;\nint main()\n{\n int result[12] = {0};\n int gold;\n while (cin>>gold) {\n if (gold < 0) {\n break;\n }\n \n int code = gold / 10;\n if (code < 4) {\n result[3] ++;\n }\n else if(code == 10) {\n result[9] ++;\n }\n else {\n result[code] ++;\n }\n }\n \n string word[] = {\"0~39\",\n \"40~49\",\n \"50~59\",\n \"60~69\",\n \"70~79\",\n \"80~89\",\n \"90~100\"};\n \n for (int i=0; i<7; i++) {\n cout<\n#include \nusing namespace std;\nint main()\n{\n\tint result[12] = {0};\n\tint gold;\n\twhile (cin>>gold) {\n\t\tif (gold < 0) {\n\t\t\tbreak;\n\t\t}\n\t\tint code = gold / 10;\n\t\tif (code < 4) {\n\t\t\tresult[3] ++;\n\t\t}\n\t\telse if(code == 10) {\n\t\t\tresult[9] ++;\n\t\t}\n\t\telse {\n\t\t\tresult[code] ++;\n\t\t}\n\t}\n\tstring word[] = {\"0~39\",\n\t\"40~49\",\n\t\"50~59\",\n\t\"60~69\",\n\t\"70~79\",\n\t\"80~89\",\n\t\"90~100\"};\n\tfor (int i=0; i<7; i++) {\n\t\tcout<体操比赛中,10名评委为5名选手打分,其分数已经存放在一个二维数组中,列出每个选手的:最高分,最低分,平均分,中位分。
\n平均分算法:除去最高分和最低分后,剩下8位评委的分数平均值。
\n中位分:10个评分从高到低排列,第5位和第6位的平均分为中位分。

", + "difficulty": "简单", + "answer_id": 53427952, + "answer_content": "
\n#include <stdio.h>\n  \nint main()\n{\n    float a[1][10],max,min,sum;\n    int i,aver;\n    max=0;\n    min=100;\n    sum=0;\n    for(i=0;i<10;i++)\n    {\n        scanf("%f",&a[0][i]);\n        if(a[0][i]>max) \n            max=a[0][i];\n        if(a[0][i]<min)\n            min=a[0][i];  \n        sum+=a[0][i];\n    }\n    aver = (sum-max-min)/8 ;\n    printf("aver:%d\\n",aver);\n    return 0;\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \nint main()\n{\n\tfloat a[1][10],max,min,sum;\n\tint i,aver;\n\tmax=0;\n\tmin=100;\n\tsum=0;\n\tfor(i=0;i<10;i++)\n\t{\n\t\tscanf(\"%f\",&a[0][i]);\n\t\tif(a[0][i]>max) \n\t\t\tmax=a[0][i];\n\t\tif(a[0][i]\n#include <stdio.h>\n\nint fun(int n,int *x,int *y)\n{\n\tint sum = 0,i;\n\tint size = 0;\n\tint dd = 1;\n\tfor (i = 1; i <= (*x);i++)\n\t{\n\t\tsum += (2*i-1);\n\t}\n\tif (sum == n)\n\t{\n\t\t*y = 2*(*x) -1;\n\t\treturn (*x);\n\t}else if (sum > n)\n\t{\n\t\t(*y) = n - (sum - (2 * (*x) -1));\n\t\tsize = 2* (*x) -1;\n\t\tdd = (*x); //第x行的第一个数\n\t\tfor (i = 2; i <= (*y);i++)\n\t\t{\n\t\t\tif(i <= (*x))\n\t\t\t\tdd *= 2;\n\t\t\telse\n\t\t\t\tdd /= 2;\n\t\t}\n\t\treturn dd;\n\t}else\n\t{\n\t\t(*x)++;\n\t\treturn fun(n,x,y);\n\t}\n}\n\nint main()\n{\n\tint n; //n项(从第1项开始)\n\tint row = 1,col = 0;\n\tint val;\n\n\trow = 1;\n\tcol = 0;\n\tprintf("请输入n:");\n\tscanf("%d",&n);\n\tval = fun(n,&row,&col);\n\tprintf("第%d项是:%d\\n",n,val);\n\treturn 0;\n}\n\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \nint fun(int n,int *x,int *y)\n{\n\tint sum = 0,i;\n\tint size = 0;\n\tint dd = 1;\n\tfor (i = 1; i <= (*x);i++)\n\t{\n\t\tsum += (2*i-1);\n\t}\n\tif (sum == n)\n\t{\n\t\t*y = 2*(*x) -1;\n\t\treturn (*x);\n\t}else if (sum > n)\n\t{\n\t\t(*y) = n - (sum - (2 * (*x) -1));\n\t\tsize = 2* (*x) -1;\n\t\tdd = (*x); \n\t\tfor (i = 2; i <= (*y);i++)\n\t\t{\n\t\t\tif(i <= (*x))\n\t\t\t\tdd *= 2;\n\t\t\telse\n\t\t\t\tdd /= 2;\n\t\t}\n\t\treturn dd;\n\t}else\n\t{\n\t\t(*x)++;\n\t\treturn fun(n,x,y);\n\t}\n}\nint main()\n{\n\tint n;\t\t\n\tint row = 1,col = 0;\n\tint val;\n\trow = 1;\n\tcol = 0;\n\tprintf(\"请输入n:\");\n\tscanf(\"%d\",&n);\n\tval = fun(n,&row,&col);\n\tprintf(\"第%d项是:%d\\n\",n,val);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470270", + "status": 1, + "keywords": "数列,递归,数学运算", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/89.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/9.json b/data_backup/cpp_code_json/9.json new file mode 100644 index 000000000..fdc37b0c3 --- /dev/null +++ b/data_backup/cpp_code_json/9.json @@ -0,0 +1,18 @@ +{ + "question_id": 7452224, + "question_title": "设计一个“石头剪刀布”游戏程序。", + "question_content": "

设计一个“石头剪刀布”游戏程序。用户和程序分别扮演猜拳双方,用户选择

石头、剪刀和布中的一项,程序随机选择另一项,与用户选择作比较,在界面中

显示最终的胜负判定。

", + "difficulty": "简单", + "answer_id": 53434132, + "answer_content": "

代码如下:如有帮助,请采纳一下,谢谢。

\n\n
\n#include <stdlib.h>\n#include <stdio.h>\n\nint main()\n{\n\tint id;\n\tint a[3]={1,2,3};\n\tint au = 0;\n\twhile(1)\n\t{\n\t\tprintf("1.剪刀,2.石头,3.布,0.退出\\n");\n\t\tscanf("%d",&id);\n\t\tif(id == 0)\n\t\t\tbreak;\n\t\tau = a[rand()%3]; //机器\n\t\tif (au == 1)\n\t\t{\n\t\t\tprintf("机器:剪刀\\t");\n\t\t\tif(id == 1)\n\t\t\t\tprintf("玩家:剪刀\\t平局\\n");\n\t\t\telse if(id == 2)\n\t\t\t\tprintf("玩家:石头\\t玩家赢\\n");\n\t\t\telse\n\t\t\t\tprintf("玩家:布\\t机器赢\\n");\n\t\t}\n\t\telse if(au == 2)\n\t\t{\n\t\t\tprintf("机器:石头\\t");\n\t\t\tif(id == 1)\n\t\t\t\tprintf("玩家:剪刀\\t机器赢\\n");\n\t\t\telse if(id == 2)\n\t\t\t\tprintf("玩家:石头\\t平局\\n");\n\t\t\telse\n\t\t\t\tprintf("玩家:布\\t玩家赢\\n");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf("机器:布\\t");\n\t\t\tif(id == 1)\n\t\t\t\tprintf("玩家:剪刀\\t玩家赢\\n");\n\t\t\telse if(id == 2)\n\t\t\t\tprintf("玩家:石头\\t机器赢\\n");\n\t\t\telse\n\t\t\t\tprintf("玩家:布\\t平局\\n");\n\t\t}\n\t}\n\t\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c语言", + "cpp": "#include \n#include \nint main()\n{\n\tint id;\n\tint a[3]={1,2,3};\n\tint au = 0;\n\twhile(1)\n\t{\n\t\tprintf(\"1.剪刀,2.石头,3.布,0.退出\\n\");\n\t\tscanf(\"%d\",&id);\n\t\tif(id == 0)\n\t\t\tbreak;\n\t\tau = a[rand()%3]; \n\t\tif (au == 1)\n\t\t{\n\t\t\tprintf(\"机器:剪刀\\t\");\n\t\t\tif(id == 1)\n\t\t\t\tprintf(\"玩家:剪刀\\t平局\\n\");\n\t\t\telse if(id == 2)\n\t\t\t\tprintf(\"玩家:石头\\t玩家赢\\n\");\n\t\t\telse\n\t\t\t\tprintf(\"玩家:布\\t机器赢\\n\");\n\t\t}\n\t\telse if(au == 2)\n\t\t{\n\t\t\tprintf(\"机器:石头\\t\");\n\t\t\tif(id == 1)\n\t\t\t\tprintf(\"玩家:剪刀\\t机器赢\\n\");\n\t\t\telse if(id == 2)\n\t\t\t\tprintf(\"玩家:石头\\t平局\\n\");\n\t\t\telse\n\t\t\t\tprintf(\"玩家:布\\t玩家赢\\n\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"机器:布\\t\");\n\t\t\tif(id == 1)\n\t\t\t\tprintf(\"玩家:剪刀\\t玩家赢\\n\");\n\t\t\telse if(id == 2)\n\t\t\t\tprintf(\"玩家:石头\\t机器赢\\n\");\n\t\t\telse\n\t\t\t\tprintf(\"玩家:布\\t平局\\n\");\n\t\t}\n\t}\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470247", + "status": 1, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/9.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/90.json b/data_backup/cpp_code_json/90.json new file mode 100644 index 000000000..0f1955076 --- /dev/null +++ b/data_backup/cpp_code_json/90.json @@ -0,0 +1,18 @@ +{ + "question_id": 7450354, + "question_title": "字符串匹配", + "question_content": "

输入两个字符串s1和s2,在s1中查找s2对应的字符串是否存在,若存在则输出它第一次出现的位置;若不存在,则输出“没有找到该字符串”。

", + "difficulty": "简单", + "answer_id": 53431020, + "answer_content": "
\n#include <string>\n#include <iostream>\n\nusing namespace std;\n\nint main()\n{\n\tstring s1, s2;\n\tcout << "请输入第一个字符串:";\n\tcin >> s1;\n\tcout << "请输入第二个字符串:";\n\tcin >> s2;\n\tif (s1.find(s2) != -1)\n\t\tcout << s1.find(s2)<<endl;\n\telse\n\t\tcout << "没有找到该字符串"<<endl;\n\tsystem("pause");\n    return 0;\n}
\n\n

\"\"

\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint main()\n{\n\tstring s1, s2;\n\tcout << \"请输入第一个字符串:\";\n\tcin >> s1;\n\tcout << \"请输入第二个字符串:\";\n\tcin >> s2;\n\tif (s1.find(s2) != -1)\n\t\tcout << s1.find(s2)<编程输入实数x,计算下面函数的值,并输出y的值,并输出y的值;\nx2         x<1\n3x-1      1≦x≦10\nx/5        x>10

", + "difficulty": "简单", + "answer_id": 53429821, + "answer_content": "

代码如下,请采纳,谢谢,不明白地方随时交流

\n\n
\n# include<stdio.h>\n# include<stdlib.h>\n\nint main(void)\n{\n\tfloat x,y;\n\n\tprintf("请输入x的值:\\n");\n\tscanf("%f",&x);\n\n\tif(x<1)\n\t{\n\t\ty = x * x;\n\t}\n\telse if(x<=10)\n\t{\n\t\ty=3*x-1;\n\t}\n\telse\n\t{\n\t\ty= x / 5;\n\t}\n\n\tprintf("y的值为:%f\\n",y);\n\n\tsystem("pause");\n\treturn 0;\n}
\n\n

 

\n", + "tag_name": "c++", + "cpp": "# include\n# include\nint main(void)\n{\n\tfloat x,y;\n\tprintf(\"请输入x的值:\\n\");\n\tscanf(\"%f\",&x);\n\tif(x<1)\n\t{\n\t\ty = x * x;\n\t}\n\telse if(x<=10)\n\t{\n\t\ty=3*x-1;\n\t}\n\telse\n\t{\n\t\ty= x / 5;\n\t}\n\tprintf(\"y的值为:%f\\n\",y);\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470171", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/91.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/92.json b/data_backup/cpp_code_json/92.json new file mode 100644 index 000000000..97d4bd763 --- /dev/null +++ b/data_backup/cpp_code_json/92.json @@ -0,0 +1,18 @@ +{ + "question_id": 7447326, + "question_title": "字符数组", + "question_content": "

编写一个以两个字符数组作为输入的函数。\n如果第二个数组包含在第一个数组中,则函数返回第一个数组中第二个数组开始的第一个索引。\n如果第二个数组不被包含在第一个数组,然后函数应该return -1\n输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’l’,’l’]  就 return 1.\n输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’n’] 就 return -1.

", + "difficulty": "简单", + "answer_id": 53427371, + "answer_content": "
\n#include <iostream>\n#include <string>\n\n\nusing namespace std;\n\nint main()\n{\n\tchar a[128],b[128];\n\tint numA, numB;\n\tcout << "请输入第一个数组元素个数:";\n\tcin >> numA;\n\tcout << "请输入第一个数组元素:";\n\tfor (int i = 0; i < numA; ++i)\n\t\tcin >> a[i];\n        cin.clear();\n\tcin.sync();\n\tcout << "请输入第二个数组元素个数:";\n\tcin >> numB;\n\tcout << "请输入第二个数组元素:";\n\tfor (int i = 0; i < numB; ++i)\n\t\tcin >> b[i];\n\tint num = 0;\t\t//第二个数组包含在第一个数组的个数\n\tstring index;\t\t//存放第二个数组在第一个数组的索引\n\tfor (int j = 0; j < numB; j++)\t\t//第二个数组的元素与第一数组的元素遍历\n\t{\n\t\tfor (int k = 0; k < numA; k++)\n\t\t{\n\t\t\tif (b[j] == a[k])\n\t\t\t{\n\t\t\t\tindex += to_string(k);\n\t\t\t\tnum++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (num == numB)\t\n\t{\n\t\tcout << "第二个数组包含在第一个数组中" << endl;\n\t\tcout << "第一个数组中第二个数组开始的第一个索引为:" << index.substr(0,1) << endl;\n\t}\n\telse\n\t\tcout << "第二个数组不被包含在第一个数组";\n\n\tsystem("pause");\n\treturn 0;\n}
\n\n

 

\n\n

\"\"

\n\n

 

\n", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nint main()\n{\n\tchar a[128],b[128];\n\tint numA, numB;\n\tcout << \"请输入第一个数组元素个数:\";\n\tcin >> numA;\n\tcout << \"请输入第一个数组元素:\";\n\tfor (int i = 0; i < numA; ++i)\n\t\tcin >> a[i];\n\tcin.clear();\n\tcin.sync();\n\tcout << \"请输入第二个数组元素个数:\";\n\tcin >> numB;\n\tcout << \"请输入第二个数组元素:\";\n\tfor (int i = 0; i < numB; ++i)\n\t\tcin >> b[i];\n\tint num = 0;\t\t\n\tstring index;\t\t\n\tfor (int j = 0; j < numB; j++)\t\t\n\t{\n\t\tfor (int k = 0; k < numA; k++)\n\t\t{\n\t\t\tif (b[j] == a[k])\n\t\t\t{\n\t\t\t\tindex += to_string(k);\n\t\t\t\tnum++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (num == numB)\t\n\t{\n\t\tcout << \"第二个数组包含在第一个数组中\" << endl;\n\t\tcout << \"第一个数组中第二个数组开始的第一个索引为:\" << index.substr(0,1) << endl;\n\t}\n\telse\n\t\tcout << \"第二个数组不被包含在第一个数组\";\n\tsystem(\"pause\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469954", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/92.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/93.json b/data_backup/cpp_code_json/93.json new file mode 100644 index 000000000..6fe2db90d --- /dev/null +++ b/data_backup/cpp_code_json/93.json @@ -0,0 +1,18 @@ +{ + "question_id": 7446071, + "question_title": "不同方式求n的阶乘", + "question_content": "

求n的阶乘(用三种不同的循环实现,提示:先从键盘输入n的值)while、do while和for

", + "difficulty": "简单", + "answer_id": 53425388, + "answer_content": "
\n#include <stdio.h>\n\nint main(void) { \n    int n;\n    printf("请输入n的值:");\n    scanf("%d",&n);\n    // while循环\n    int temp=n,sum=1;\n    while(temp>1){\n        sum*=temp;\n        temp--;\n    }\n    printf("%d的阶乘是%d\\n",n,sum);\n    \n    // do while循环\n    temp=n;\n    sum=1;\n    do{\n        sum*=temp;\n        temp--;\n    }while(temp>1);\n    printf("%d的阶乘是%d\\n",n,sum);\n    \n    // for循环\n    temp=n;\n    sum=1;\n    for(;temp>1;temp--){\n        sum*=temp;;\n    }\n    printf("%d的阶乘是%d\\n",n,sum);\n    return 0;\n}
\n", + "tag_name": "c语言", + "cpp": "#include \nint main(void) { \n\tint n;\n\tprintf(\"请输入n的值:\");\n\tscanf(\"%d\",&n);\n\tint temp=n,sum=1;\n\twhile(temp>1){\n\t\tsum*=temp;\n\t\ttemp--;\n\t}\n\tprintf(\"%d的阶乘是%d\\n\",n,sum);\n\ttemp=n;\n\tsum=1;\n\tdo{\n\t\tsum*=temp;\n\t\ttemp--;\n\t}while(temp>1);\n\tprintf(\"%d的阶乘是%d\\n\",n,sum);\n\ttemp=n;\n\tsum=1;\n\tfor(;temp>1;temp--){\n\t\tsum*=temp;;\n\t}\n\tprintf(\"%d的阶乘是%d\\n\",n,sum);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469955", + "status": 1, + "keywords": "循环", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/93.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/94.json b/data_backup/cpp_code_json/94.json new file mode 100644 index 000000000..22a097a93 --- /dev/null +++ b/data_backup/cpp_code_json/94.json @@ -0,0 +1,18 @@ +{ + "question_id": 884449, + "question_title": "数字归类", + "question_content": "题目描述\n一个数里面若含有数字1,则归类到1字类,含有数字2,则归类到2字类,所以一个数可能同时归类到不同的数字类。对于0、1、2、3、4、5、6、7、8、9这十个数字类,因研究需要,急于想知道某一堆数中,究竟归类到这些数字类的个数。\n样例输入\n123 456 175 2 61 9998 12 5053 382\n样例输出\n0: 1\n1: 4\n2: 4\n3: 3\n4: 1\n5: 3\n6: 2\n7: 1\n8: 2\n9: 1\n提示\n注意:输出结果中冒号后面有空格", + "difficulty": "中等", + "answer_id": 1023453, + "answer_content": "\n```\n#include \n#include \n\nint result[10];\n\nint main(void) {\n\tmemset(result, 0, sizeof(int) * 10);\n\tint n;\n\tint arr[10];\n\twhile (scanf(\"%d\", &n) != EOF)\n\t{\n\t\tmemset(arr, 0, sizeof(int) * 10);\n\t\tif (n == 0) arr[0] = 1;\n\t\twhile (n > 0)\n\t\t{\n\t\t\tarr[n % 10] = 1;\n\t\t\tn = n / 10;\n\t\t}\n\t\tfor (int i = 0; i < 10; i++)\n\t\t\tresult[i] += arr[i];\n\t}\n\tfor (int i = 0; i < 10; i++)\n\t\tprintf(\"%d: %d\\n\", i, result[i]);\n\treturn 0;\n}\n\n```\n\nhttps://www.ideone.com/EMaE5P \n在线编译调试通过\n\n# 如果问题解决,请采纳", + "tag_name": "c++", + "cpp": "#include \n#include \nint result[10];\nint main(void) {\n\tmemset(result, 0, sizeof(int) * 10);\n\tint n;\n\tint arr[10];\n\twhile (scanf(\"%d\", &n) != EOF)\n\t{\n\t\tmemset(arr, 0, sizeof(int) * 10);\n\t\tif (n == 0) arr[0] = 1;\n\t\twhile (n > 0)\n\t\t{\n\t\t\tarr[n % 10] = 1;\n\t\t\tn = n / 10;\n\t\t}\n\t\tfor (int i = 0; i < 10; i++)\n\t\t\tresult[i] += arr[i];\n\t}\n\tfor (int i = 0; i < 10; i++)\n\t\tprintf(\"%d: %d\\n\", i, result[i]);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469856", + "status": 1, + "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/94.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/95.json b/data_backup/cpp_code_json/95.json new file mode 100644 index 000000000..39f46cdf0 --- /dev/null +++ b/data_backup/cpp_code_json/95.json @@ -0,0 +1,18 @@ +{ + "question_id": 7458543, + "question_title": "输入一个数查找比它小的元素", + "question_content": "

一个整型数组有10元素,请先给这10个元素赋值,然后随便输入一个数,最后输出数组中比这个数小的所有元素,每个数用空格隔开,如果没有找到,则输出not find。
\n 

\n

\"\"\n 

", + "difficulty": "中等", + "answer_id": 53443165, + "answer_content": "

代码如下:

\n\n
\n#include <stdio.h>\nint main()\n{\n\tint a[10],i,n;\n\tint isfind = 0;\n\tprintf("please set array values:");\n\tfor(i=0;i<10;i++)\n\t\tscanf("%d",&a[i]);\n\n\tprintf("please enter one num:");\n\tscanf("%d",&n);\n\tfor (i=0;i<10;i++)\n\t{\n\t\tif(a[i] < n)\n\t\t{\n\t\t\tisfind = 1;\n\t\t\tprintf("%d ",a[i]);\n\t\t}\n\t}\n\t\n\tif(isfind)\n\t\tprintf("\\n");\n\telse\n\t\tprintf("not find\\n");\n\t\n\t\n\treturn 0;\n}
\n", + "tag_name": "c语言", + "cpp": "#include \nint main()\n{\n\tint a[10],i,n;\n\tint isfind = 0;\n\tprintf(\"please set array values:\");\n\tfor(i=0;i<10;i++)\n\t\tscanf(\"%d\",&a[i]);\n\tprintf(\"please enter one num:\");\n\tscanf(\"%d\",&n);\n\tfor (i=0;i<10;i++)\n\t{\n\t\tif(a[i] < n)\n\t\t{\n\t\t\tisfind = 1;\n\t\t\tprintf(\"%d \",a[i]);\n\t\t}\n\t}\n\tif(isfind)\n\t\tprintf(\"\\n\");\n\telse\n\t\tprintf(\"not find\\n\");\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600470172", + "status": 1, + "keywords": "算法高阶,数论算法,元素的幂,算法问题选编", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/95.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/96.json b/data_backup/cpp_code_json/96.json new file mode 100644 index 000000000..0462582c5 --- /dev/null +++ b/data_backup/cpp_code_json/96.json @@ -0,0 +1,17 @@ +{ + "question_id": 237869, + "question_title": "编写程序,输入任意一个含有空格的字符串(至少10个字符),删除指定字符后输出该字符串。", + "question_content": "编写程序,输入任意一个含有空格的字符串(至少10个字符),删除指定字符后输出该字符串。例如,输入“jiangsu123”和删除位置5,则输出“jiansu123”。", + "difficulty": "简单", + "answer_id": 218941, + "answer_content": "\n\n```\n #include \n#include \nusing namespace std;\n\nint main()\n{\n char s1[100];\n char s2[100];\n int n = 0;\n\tcin.getline(s1, 100);\n\tcin.getline(s2, 100);\n cin >> n;\n\tint i;\n\tint ls2 = strlen(s2);\n\tfor (i = strlen(s1); i >= n; i--)\n\t\ts1[i + ls2] = s1[i];\n\tfor (i = 0; i < ls2; i++)\n\t\ts1[n + i] = s2[i];\n cout << s1 << endl;\n return 0;\n}\n```\n\n", + "tag_name": "c++", + "cpp": " #include \n#include \nusing namespace std;\nint main()\n{\n\tchar s1[100];\n\tchar s2[100];\n\tint n = 0;\n\tcin.getline(s1, 100);\n\tcin.getline(s2, 100);\n\tcin >> n;\n\tint i;\n\tint ls2 = strlen(s2);\n\tfor (i = strlen(s1); i >= n; i--)\n\t\ts1[i + ls2] = s1[i];\n\tfor (i = 0; i < ls2; i++)\n\t\ts1[n + i] = s2[i];\n\tcout << s1 << endl;\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469857", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/96.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/97.json b/data_backup/cpp_code_json/97.json new file mode 100644 index 000000000..8eeaccdbe --- /dev/null +++ b/data_backup/cpp_code_json/97.json @@ -0,0 +1,18 @@ +{ + "question_id": 1080248, + "question_title": "擅长编码的小k", + "question_content": "题目描述\n小k不仅擅长数学,也擅长编码。有一种编码方式如下:\n首先写下文本中间的字符(如果文本中的字符编号为1..n,那么中间一个字符的编号为(n+1)DIV 2,其中DIV为整除的意思),然后 用这个方法递归地写下左边,最后再按这个方法递归地写下右边。例如,单词为orthography则其编码为gtorhoprahy。即先写中间的那个字符g,再对ortho递归地编码,最后将raphy递归地编码就得到了gtorhoprahy。\n给一个原来的文本,求出编码后的 文本。\n输入\n一行字符,表示原始的文本内容。\n输出\n一行字符,表示编码后的文本内容。\n样例\n输入 \northography\n输出 \ngtorhoprahy\n提示\n100%的数据,字符串长度不超过20000", + "difficulty": "困难", + "answer_id": 1285384, + "answer_content": "利用递归,先输出中间的字符,然后输出递归输出左边的,再递归输出右边的。代码如下:\n\n```\n#include \n#include \nusing namespace std;\n\nvoid shuchu(char *a,int m, int n)\n{\n if(n<=0||m<=0||m>n)\n {\n return;\n }\n else\n {\n cout << a[(m+n)/2];\n shuchu(a,m,(m+n)/2-1);\n shuchu(a,(m+n)/2+1,n);\n }\n}\n\nint main()\n{\n char a[20000];\n char b[20001];\n cin >> a;\n for(int i=0; i<20000; i++)\n {\n b[i+1] = a[i];\n }\n int n = strlen(a);\n shuchu(b,1,n);\n return 0;\n}\n\n\n```", + "tag_name": "c++", + "cpp": "#include \n#include \nusing namespace std;\nvoid shuchu(char *a,int m, int n)\n{\n\tif(n<=0||m<=0||m>n)\n\t{\n\t\treturn;\n\t}\n\telse\n\t{\n\t\tcout << a[(m+n)/2];\n\t\tshuchu(a,m,(m+n)/2-1);\n\t\tshuchu(a,(m+n)/2+1,n);\n\t}\n}\nint main()\n{\n\tchar a[20000];\n\tchar b[20001];\n\tcin >> a;\n\tfor(int i=0; i<20000; i++)\n\t{\n\t\tb[i+1] = a[i];\n\t}\n\tint n = strlen(a);\n\tshuchu(b,1,n);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469956", + "status": 1, + "keywords": "算法初阶,基础知识,分治策略,用主方法求解递归式", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/97.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/98.json b/data_backup/cpp_code_json/98.json new file mode 100644 index 000000000..306f070a3 --- /dev/null +++ b/data_backup/cpp_code_json/98.json @@ -0,0 +1,18 @@ +{ + "question_id": 7412708, + "question_title": "水果计费系统", + "question_content": "

本关任务:编写程序,有五种水果,apple、banana、orage、strawberry、pear,每一种有一个价格(浮点小数),由老板输入,请提示用户选择什么水果,购买数量(按照斤两),然后将总价显示出来。

", + "difficulty": "简单", + "answer_id": 53364151, + "answer_content": "
\n#include<stdio.h>\n\nint main(){\n\ttypedef enum {apple, banana, orange, strawberry, pear} fruits;//水果枚举类型 \n\tdouble prices[5];             //价格数组\n\tfruits purchase;             //枚举购买水果 \n\tint fruit;                   //水果编号的输入 \n\tdouble amount;               //总价 \n\tfor(int i = 0; i < 5; i++)\n\t\tscanf("%lf", &prices[i]);//老板输入价格 \n\tprintf("水果编号:1.苹果  2.香蕉  3.橘子  4.草莓  5.梨\\n");\n\tprintf("请输入购买的水果(1~5),以及购买数量(按照斤两):\\n");//提示\n\tscanf("%d %lf", &fruit, &amount);\n\tpurchase = (fruits)fruit;     //输入的编号对应水果 \n\tprintf("总价为:%.3lf", prices[purchase-1]*amount);\n\treturn 0; \n}
\n\n

 

", + "tag_name": "c语言", + "cpp": "#include\nint main(){\n\ttypedef enum {apple, banana, orange, strawberry, pear} fruits;\n\tdouble prices[5];\t\t\t \n\tfruits purchase;\t\t\t \n\tint fruit;\t\t\t\t \n\tdouble amount;\t\t\t \n\tfor(int i = 0; i < 5; i++)\n\t\tscanf(\"%lf\", &prices[i]);\n\tprintf(\"水果编号:1.苹果 2.香蕉 3.橘子 4.草莓 5.梨\\n\");\n\tprintf(\"请输入购买的水果(1~5),以及购买数量(按照斤两):\\n\");\n\tscanf(\"%d %lf\", &fruit, &amount);\n\tpurchase = (fruits)fruit;\t \n\tprintf(\"总价为:%.3lf\", prices[purchase-1]*amount);\n\treturn 0; \n}", + "topic_link": "https://bbs.csdn.net/topics/600470173", + "status": 1, + "keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/98.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/cpp_code_json/99.json b/data_backup/cpp_code_json/99.json new file mode 100644 index 000000000..6b26323ed --- /dev/null +++ b/data_backup/cpp_code_json/99.json @@ -0,0 +1,18 @@ +{ + "question_id": 1057027, + "question_title": "已知一个浮点数A(0\n#include \nint main () {\nfloat A = 0.2f;\nint x = 0;\nif (A < 0) { x = 1; A = 1/A; }\nfloat delta = 1;\nint B = 1, C = 1;\ndo\n{\nC = (int)(B * A);\ndelta = fabs(C/(float)B-A);\nB++;\n}\nwhile (delta > 0.000001); //如果你要高精度,就改小,否则改大\nif (x == 0)\nprintf(\"%d / %d\", C, B - 1);\nelse\nprintf(\"%d / %d\", B - 1, C);\nreturn 0;\n}\n\n```\n# 问题解决请点采纳", + "tag_name": "c++", + "cpp": "#include \n#include \nint main () {\n\tfloat A = 0.2f;\n\tint x = 0;\n\tif (A < 0) { x = 1; A = 1/A; }\n\tfloat delta = 1;\n\tint B = 1, C = 1;\n\tdo\n\t{\n\t\tC = (int)(B * A);\n\t\tdelta = fabs(C/(float)B-A);\n\t\tB++;\n\t}\n\twhile (delta > 0.000001); \n\tif (x == 0)\n\t\tprintf(\"%d / %d\", C, B - 1);\n\telse\n\t\tprintf(\"%d / %d\", B - 1, C);\n\treturn 0;\n}", + "topic_link": "https://bbs.csdn.net/topics/600469957", + "status": 1, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/99.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/0.json b/data_backup/java_code_json/0.json new file mode 100644 index 000000000..680481d0f --- /dev/null +++ b/data_backup/java_code_json/0.json @@ -0,0 +1,18 @@ +{ + "question_id": 382917, + "question_title": "改写字符串", + "question_content": "键盘录入一个字符串,将字符串中的大写改成小写,小写改成大写,数字改成*。例如heLLO123,输出后为HEllo***", + "difficulty": "简单", + "answer_id": 418046, + "answer_content": "\n\n```\n import java.util.Scanner;\n\n/**\n *\n * @author sunzc 转换字符串,大写变小写,小写变大写,数字不变,其他变为*\n */\npublic class Transfer {\n public static void main(String[] args) {\n // String str = \"ABC123abcfadfjbJBHJHJDsa\";\n String str = \"\";\n Scanner s = new Scanner(System.in);\n System.out.println(\"请输入您想输入的字符串:\");\n str = s.next();\n StringBuffer sb = new StringBuffer();\n int i;\n // char ch;\n for (i = 0; i <= str.length() - 1; i++) {// 遍历字符串\n char ch;\n\n // 通过str.charAt(i)遍历出字符串中每个字符\n if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {// 判断字符是否在a-z之间(小写)\n ch = (char) (str.charAt(i) - 32); // 如果为小写则转换为相应大写,赋值给ch\n } else if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {// 判断字符是否在A-Z之间(大写)\n ch = (char) (str.charAt(i) + 32); // 如果为大写则转换为相应小写,赋值给ch\n } else if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {// 判断字符是否在0-9之间(数字)\n ch = '*'; // 如果为数字,则转为*号\n } else {\n ch = str.charAt(i); // 将原字符赋值给ch\n }\n sb.append(ch); // 将字符追加到sb序列\n }\n String trStr = sb.toString(); // 将StringBuffer转换为String类型\n System.out.println(sb.toString());\n }\n\n}\n```\n\n", + "tag_name": "java", + "java": "import java.util.Scanner;\npublic class Transfer {\n\tpublic static void main(String[] args) {\n\tString str = \"\";\n\tScanner s = new Scanner(System.in);\n\tSystem.out.println(\"请输入您想输入的字符串:\");\n\tstr = s.next();\n\tStringBuffer sb = new StringBuffer();\n\tint i;\n\tfor (i = 0; i <= str.length() - 1; i++) {\n\t\tchar ch;\n\t\tif (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {\n\t\t\tch = (char) (str.charAt(i) - 32); \n\t\t} else if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {\n\t\t\tch = (char) (str.charAt(i) + 32); \n\t\t} else if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {\n\t\t\tch = '*'; \n\t\t} else {\n\t\t\tch = str.charAt(i); \n\t\t}\n\t\tsb.append(ch); \n\t}\n\tString trStr = sb.toString(); \n\tSystem.out.println(sb.toString());\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600469971", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/0.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/1.json b/data_backup/java_code_json/1.json new file mode 100644 index 000000000..8a6bbb363 --- /dev/null +++ b/data_backup/java_code_json/1.json @@ -0,0 +1,18 @@ +{ + "question_id": 1071564, + "question_title": "显示是哪个线程输出的字母", + "question_content": "编写一个程序,创建两个线程,要求分别输出26个字母。在输出结果时,要显示是哪个线程输出的字母。注:26个字母可以首先定义一个字符a,在a的基础上循环加1实现。", + "difficulty": "中等", + "answer_id": 1274548, + "answer_content": "\n```\npackage help;\n\npublic class help {\n\tpublic static void main(String[] args) {\n\t\tThread a=new ThreadA();//创建线程\n\t\ta.start();//线程启动\n\t\tThread b=new ThreadB();\n\t\tb.start();\n\t}\n}\nclass ThreadA extends Thread implements Runnable{//利用Runnable接口使这个类变成一个可运行的类\n\tpublic void run() {//线程的标配,run方法\n\t\tchar[] arr= {'a','b','c','d'};//先创建一个字符数组,为下面的遍历做准备(把a到z都写在里面就可以了,这里我没有写全)\n\t\tfor(char x:arr) {//用foreach循环遍历上面的字符数组,就可以轮流输出了\n\t\t\tSystem.out.println(\"线程A输出:\"+x);//输出每个遍历出来的元素\n\t\t}\n\t}\n}\nclass ThreadB extends Thread implements Runnable{//与上面的原理一样\n\tpublic void run() {\n\t\tchar[] arr= {'a','b','c','d'};\n\t\tfor(char x:arr) {\n\t\t\tSystem.out.println(\"线程B输出:\"+x);\n\t\t}\n\t}\n}\n\n```", + "tag_name": "java", + "java": "public class help {\n\tpublic static void main(String[] args) {\n\t\tThread a=new ThreadA();\n\t\ta.start();\n\t\tThread b=new ThreadB();\n\t\tb.start();\n\t}\n}\nclass ThreadA extends Thread{\n\tpublic void run() {\n\t\tchar[] arr= {'a','b','c','d'};\n\t\tfor(char x:arr) {\n\t\t\tSystem.out.println(\"线程A输出:\"+x);\n\t\t}\n\t}\n}\nclass ThreadB extends Thread{\n\tpublic void run() {\n\t\tchar[] arr= {'a','b','c','d'};\n\t\tfor(char x:arr) {\n\t\t\tSystem.out.println(\"线程B输出:\"+x);\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469972", + "status": 0, + "keywords": "算法高阶,多线程算法,算法问题选编,动态多线程基础", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/1.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/10.json b/data_backup/java_code_json/10.json new file mode 100644 index 000000000..289f828df --- /dev/null +++ b/data_backup/java_code_json/10.json @@ -0,0 +1,18 @@ +{ + "question_id": 1086384, + "question_title": "按要求编写字符界面", + "question_content": "编写一个字符界面的Java Application 程序,接受用户输入的10个整数,并输出这10个整数的最大值和最小值。", + "difficulty": "简单", + "answer_id": 1293295, + "answer_content": "\n```\nimport java.util.Scanner;\npublic class MaxMin {\n public static void main(String[] args) {\n Arrays array = new Arrays();\n array.setArr();\n int max=array.getMax();\n int min=array.getMin();\n System.out.println(\"数组中最大值=\"+max);\n System.out.println(\"数组中最小值=\"+min);\n }\n }\n class Arrays {\n private int[] arr;\n // 构造方法初始化\n public Arrays() {\n arr = new int[10] ;\n for(int i = 0; i i)\n min= i;\n }\n return min; \n }\n}\n\n```\nhttps://blog.csdn.net/qq_44473695/article/details/102326683", + "tag_name": "java", + "java": "import java.util.Scanner;\npublic class MaxMin {\n\tpublic static void main(String[] args) {\n\t\tArrays array = new Arrays();\n\t\tarray.setArr();\n\t\tint max=array.getMax();\n\t\tint min=array.getMin();\n\t\tSystem.out.println(\"数组中最大值=\"+max);\n\t\tSystem.out.println(\"数组中最小值=\"+min);\n\t}\n}\nclass Arrays {\n\tprivate int[] arr;\n\tpublic Arrays() {\n\t\tarr = new int[10] ;\n\t\tfor(int i = 0; i i)\n\t\t\t\tmin= i;\n\t\t}\n\t\treturn min; \n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470281", + "status": 1, + "keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/10.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/11.json b/data_backup/java_code_json/11.json new file mode 100644 index 000000000..17f0f23a7 --- /dev/null +++ b/data_backup/java_code_json/11.json @@ -0,0 +1,18 @@ +{ + "question_id": 384519, + "question_title": "生成随机字符串", + "question_content": "生成一个由大写字母和数字组成的6位随机字符串,并且字符串不重复", + "difficulty": "简单", + "answer_id": 420998, + "answer_content": "public static char[] generate() {\n\t\t\n\t\tchar[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',\n\t\t\t\t'K', 'L', 'M', 'N', 'O', 'P','Q', 'R', 'S', 'T', 'U', 'V',\n\t\t\t\t'W', 'X', 'Y', 'Z','0','1','2','3','4','5','6','7','8','9'};\n\t\tboolean[] flags = new boolean[letters.length];\n\t\tchar[] chs = new char[6];\n\t\tfor (int i = 0; i < chs.length; i++) {\n\t\t\tint index;\n\t\t\tdo {\n\t\t\t\tindex = (int) (Math.random() * (letters.length));\n\t\t\t} while (flags[index]);// 判断生成的字符是否重复\n\t\t\tchs[i] = letters[index];\n\t\t\tflags[index] = true;\n\t\t}\n\t\treturn chs;\n\t}", + "tag_name": "java", + "java": "class java_384519 {\n\tpublic static char[] generate() {\n\tchar[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',\n\t\t'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };\n\tboolean[] flags = new boolean[letters.length];\n\tchar[] chs = new char[6];\n\tfor (int i = 0; i < chs.length; i++) {\n\t int index;\n\t do {\n\t\tindex = (int) (Math.random() * (letters.length));\n\t } while (flags[index]);\n\t chs[i] = letters[index];\n\t flags[index] = true;\n\t}\n\treturn chs;\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600470188", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/11.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/12.json b/data_backup/java_code_json/12.json new file mode 100644 index 000000000..3020cef2d --- /dev/null +++ b/data_backup/java_code_json/12.json @@ -0,0 +1,18 @@ +{ + "question_id": 7443813, + "question_title": "求公式的值", + "question_content": "求 1-1/2!-1/3! -... -1/10! ", + "difficulty": "简单", + "answer_id": 53421121, + "answer_content": "

代码如下:

\n\n
\n\npublic class TEST {\n\t\n\tpublic static double jiecheng(int n){\n\t\tdouble s = 1;\n\t\tfor(int i = 1; i <=n;i++)\n\t\t\ts *= i;\n\t\treturn s;\n\t}\n\tpublic static double sum(int n){\n\t\tdouble sum = 0.0;\n\t\tint s = 1;\n\t\tfor(int i = 1; i <=n; i++){\n\t\t\tsum += s/jiecheng(i);\n\t\t\ts = -s;\n\t\t}\n\t\treturn sum;\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tint n = 10;\n\t\tdouble ss = sum(n);\n\t\tSystem.out.println(ss);\n\t\t\n\t\t\n\t}\n\t\n\t\n}\n
\n", + "tag_name": "java", + "java": "public class TEST {\n\tpublic static double jiecheng(int n) {\n\t\tdouble s = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\ts *= i;\n\t\treturn s;\n\t}\n\tpublic static double sum(int n) {\n\t\tdouble sum = 0.0;\n\t\tint s = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tsum += s / jiecheng(i);\n\t\t\ts = -s;\n\t\t}\n\t\treturn sum;\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\tint n = 10;\n\t\tdouble ss = sum(n);\n\t\tSystem.out.println(ss);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470282", + "status": 1, + "keywords": "数学,阶乘,算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/12.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/13.json b/data_backup/java_code_json/13.json new file mode 100644 index 000000000..50b0fa96b --- /dev/null +++ b/data_backup/java_code_json/13.json @@ -0,0 +1,18 @@ +{ + "question_id": 7454234, + "question_title": "用数组写水仙花数", + "question_content": "定义一个整型数组 a[7],在控制台输入任意的 7 个整数给数组赋值,输出数组中所 有的“水仙花数”。“水仙花数”是指一个三位数其各位数字的立方和等于该数本身。", + "difficulty": "简单", + "answer_id": 53436906, + "answer_content": "

如有帮助,请采纳。点击我回答右上角【采纳】按钮。

\n\n
\nimport java.util.Scanner;\npublic class Test {\n\tpublic static void main(String[] args) {\n        Scanner in=new Scanner(System.in);\n        int arr[]=new int[7];\n        System.out.println("请输入7个三位数:");\n        for(int i=0;i<arr.length;i++){\n        \tarr[i]=in.nextInt();\n        }\n        System.out.println("数组中的水花仙数为:");\n        for(int i=0;i<arr.length;i++){\n            int x =arr[i]/100;\n            int y =arr[i]/10%10;\n            int z =arr[i]%10;\n            if(i==x*x*x+y*y*y+z*z*z)\n                System.out.println(i);\n        }\n    }\n}\n
\n\n

 

\n", + "tag_name": "java", + "java": "import java.util.Scanner;\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint arr[] = new int[7];\n\t\tSystem.out.println(\"请输入7个三位数:\");\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tarr[i] = in.nextInt();\n\t\t}\n\t\tSystem.out.println(\"数组中的水花仙数为:\");\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tint x = arr[i] / 100;\n\t\t\tint y = arr[i] / 10 % 10;\n\t\t\tint z = arr[i] % 10;\n\t\t\tif (arr[i] == x * x * x + y * y * y + z * z * z)\n\t\t\t\tSystem.out.println(i);\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470189", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/13.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/14.json b/data_backup/java_code_json/14.json new file mode 100644 index 000000000..9b234f3b1 --- /dev/null +++ b/data_backup/java_code_json/14.json @@ -0,0 +1,18 @@ +{ + "question_id": 150738, + "question_title": "对给定的两个日期之间的日期进行遍历", + "question_content": "对给定的两个日期之间的日期进行遍历,比如startTime 是 2014-07-11;endTime 是 2014-08-11 如何把他们之间的日期获取并遍历出来。", + "difficulty": "简单", + "answer_id": 72266, + "answer_content": "import java.text.ParseException;\nimport java.text.SimpleDateFormat;\nimport java.util.ArrayList;\nimport java.util.Date;\nimport java.util.List;\n\npublic class SplitTime {\n\n\tprivate static List dateSplit(Date startDate, Date endDate)\n\t\t\tthrows Exception {\n\t\tif (!startDate.before(endDate))\n\t\t\tthrow new Exception(\"开始时间应该在结束时间之后\");\n\t\tLong spi = endDate.getTime() - startDate.getTime();\n\t\tLong step = spi / (24 * 60 * 60 * 1000);// 相隔天数\n\n\t\tList dateList = new ArrayList();\n\t\tdateList.add(endDate);\n\t\tfor (int i = 1; i <= step; i++) {\n\t\t\tdateList.add(new Date(dateList.get(i - 1).getTime()\n\t\t\t\t\t- (24 * 60 * 60 * 1000)));// 比上一天减一\n\t\t}\n\t\treturn dateList;\n\t}\n\n\tpublic static void main(String[] args) throws ParseException {\n\t\ttry {\n\t\t\tSimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd\");\n\t\t\tDate start = sdf.parse(\"2015-4-20\");\n\t\t\tDate end = sdf.parse(\"2015-5-2\");\n\t\t\tList lists = dateSplit(start, end);\n\t\t\tif (!lists.isEmpty()) {\n\t\t\t\tfor (Date date : lists) {\n\t\t\t\t\tSystem.out.println(sdf.format(date));\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t}\n\t}\n\n}\n运行结果:\n2015-05-02\n2015-05-01\n2015-04-30\n2015-04-29\n2015-04-28\n2015-04-27\n2015-04-26\n2015-04-25\n2015-04-24\n2015-04-23\n2015-04-22\n2015-04-21\n2015-04-20", + "tag_name": "java", + "java": "import java.text.ParseException;\nimport java.text.SimpleDateFormat;\nimport java.util.ArrayList;\nimport java.util.Date;\nimport java.util.List;\npublic class SplitTime {\n\tprivate static List dateSplit(Date startDate, Date endDate) throws Exception {\n\t\tif (!startDate.before(endDate))\n\t\t\tthrow new Exception(\"开始时间应该在结束时间之后\");\n\t\tLong spi = endDate.getTime() - startDate.getTime();\n\t\tLong step = spi / (24 * 60 * 60 * 1000);\n\t\tList dateList = new ArrayList();\n\t\tdateList.add(endDate);\n\t\tfor (int i = 1; i <= step; i++) {\n\t\t\tdateList.add(new Date(dateList.get(i - 1).getTime() - (24 * 60 * 60 * 1000)));\n\t\t}\n\t\treturn dateList;\n\t}\n\tpublic static void main(String[] args) throws ParseException {\n\t\ttry {\n\t\t\tSimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd\");\n\t\t\tDate start = sdf.parse(\"2015-4-20\");\n\t\t\tDate end = sdf.parse(\"2015-5-2\");\n\t\t\tList lists = dateSplit(start, end);\n\t\t\tif (!lists.isEmpty()) {\n\t\t\t\tfor (Date date : lists) {\n\t\t\t\t\tSystem.out.println(sdf.format(date));\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470283", + "status": 1, + "keywords": "遍历", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/14.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/15.json b/data_backup/java_code_json/15.json new file mode 100644 index 000000000..973f88f65 --- /dev/null +++ b/data_backup/java_code_json/15.json @@ -0,0 +1,18 @@ +{ + "question_id": 707980, + "question_title": "字符串排序", + "question_content": "用main方法排序(按首字母或按字符串长度)\n要求:\n①输出原数组和排序后的数组\n②若有“,”“.”不能进行排序,并将不符合排序要求的数组打印出来\n③不能用API,可用选择、冒泡、快速", + "difficulty": "简单", + "answer_id": 641196, + "answer_content": "\n\n```\nclass Untitled {\n\tpublic static void main(String[] args) {\n\t\tint num;\n\t\tSystem.out.println(\"请输入数组元素长度:\");\n\t\tScanner in=new Scanner(System.in);\n\t\tnum=in.nextInt();\n\t\tSystem.out.println(\"请输入字符串:\");\n\t\tString str[]=new String[num];\n\t\tfor(int count=0;count 0)\n\t\t{\n\t\t\tr *= (n % 10);\n\t\t\tn /= 10;\n\t\t}\n\t\treturn r;\n\t}\n public static void main(String []args) {\n\t\tint n = 99;\n\t\tint x = n;\n\t\tint t = 0;\n\t\twhile (x >= 10)\n\t\t{\n\t\t\tx = splitmul(n);\n\t\t\tSystem.out.println(x);\n\t\t\tn = x;\n\t\t\tt++;\n\t\t}\n\t\tSystem.out.println(t + \"次\");\n\n }\n}\n```\n\n81\n8\n2次", + "tag_name": "java", + "java": "public class HelloWorld {\n\tpublic static int splitmul(int n) {\n\t\tint r = 1;\n\t\twhile (n > 0) {\n\t\t\tr *= (n % 10);\n\t\t\tn /= 10;\n\t\t}\n\t\treturn r;\n\t}\n\tpublic static void main(String[] args) {\n\t\tint n = 99;\n\t\tint x = n;\n\t\tint t = 0;\n\t\twhile (x >= 10) {\n\t\t\tx = splitmul(n);\n\t\t\tSystem.out.println(x);\n\t\t\tn = x;\n\t\t\tt++;\n\t\t}\n\t\tSystem.out.println(t + \"次\");\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469974", + "status": 1, + "keywords": "算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/16.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/17.json b/data_backup/java_code_json/17.json new file mode 100644 index 000000000..bd9ba6f80 --- /dev/null +++ b/data_backup/java_code_json/17.json @@ -0,0 +1,18 @@ +{ + "question_id": 803899, + "question_title": "随机抽样", + "question_content": "从数组a[]={1,2,3,4,5,6,7,8,9,10}中随机抽取5个数且不重复", + "difficulty": "简单", + "answer_id": 898226, + "answer_content": "这里只有十个元素,用 Random 的 nextInt() 对 10 求余,产生 10 以内的元素作为访问角标。\n同时需要维护一个 Set 判断是否重复,demo:\n\n```\npublic static void main(String[] args) {\n int a[]={1,2,3,4,5,6,7,8,9,10};\n Random r = new Random();\n int count = 10;\n while(count-->0){\n Set result = new HashSet(5);\n while(result.size()<5){\n int index = r.nextInt(10)%10;//范围为 10\n int currentData = a[index];\n if(result.contains(currentData)){\n continue;\n }\n\n System.out.print(\"随机加入:\"+ currentData);\n result.add(currentData);\n }\n System.out.println(\"第\"+count+\"次,last随机数:\"+result);\n }\n\n\n }\n```\nrandom 的随机性还是可以的,基本上很少重复的。", + "tag_name": "java", + "java": "import java.util.HashSet;\nimport java.util.Random;\nimport java.util.Set;\nclass java_803899 {\n\tpublic static void main(String[] args) {\n\t\tint a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n\t\tRandom r = new Random();\n\t\tint count = 10;\n\t\twhile (count-- > 0) {\n\t\t\tSet result = new HashSet(5);\n\t\t\twhile (result.size() < 5) {\n\t\t\t\tint index = r.nextInt(10) % 10;\n\t\t\t\tint currentData = a[index];\n\t\t\t\tif (result.contains(currentData)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tSystem.out.print(\"随机加入:\" + currentData);\n\t\t\t\tresult.add(currentData);\n\t\t\t}\n\t\t\tSystem.out.println(\"第\" + count + \"次,last随机数:\" + result);\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470284", + "status": 1, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/17.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/18.json b/data_backup/java_code_json/18.json new file mode 100644 index 000000000..31ad4fac4 --- /dev/null +++ b/data_backup/java_code_json/18.json @@ -0,0 +1,18 @@ +{ + "question_id": 707984, + "question_title": "发奖金问题", + "question_content": "过年了,村里要庆祝。村长说,村里有一笔钱作为奖金,让每个人写一个纸条上来,谁写的数目与奖金最接近,就算猜中,这笔奖金就归谁,如果多人猜中,则平分。编写程序,算算都有哪些人得到奖金?多少?", + "difficulty": "中等", + "answer_id": 641210, + "answer_content": "\n\n```\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Arrays;\n\nclass Q707984 {\n\tpublic static void main(String[] args) {\n\t\tint award = 100;\n\t\tString[] people = { \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\" };\n\t\tInteger[] guess = { 75, 70, 80, 120, 100, 110, 100, 45 };\n\t\t\n\t\tInteger[] ordered = new Integer[people.length];\n\t\tfor (int i = 0; i < ordered.length; i++) ordered[i] = i;\n\t\tArrays.sort(ordered, new Comparator() {\n\t\t\t@Override\n\t\t\tpublic int compare(Integer a, Integer b) {\n\t\t\t\tint x = guess[a] - award > 0 ? guess[a] - award : award - guess[a];\n\t\t\t\tint y = guess[b] - award > 0 ? guess[b] - award : award - guess[b];\n\t\t\t\treturn x - y;\n\t\t\t}\n\t\t});\n\t\tint maxp = 0;\n\t\tint i = 0;\n\t\twhile (guess[ordered[i++]] == award) maxp++;\n\t\tif (maxp <= 1)\n\t\t\tSystem.out.println(people[ordered[0]] + \"一人得奖\" + award + \"元。\");\n\t\telse\n\t\t{\n\t\t\tfor (i = 0; i < maxp; i++)\n\t\t\t\tSystem.out.print(people[ordered[i]] + \" \");\n\t\t\tSystem.out.println(\"共同得奖\" + award / (float)(maxp) + \"元。\");\n\t\t}\n\t}\n}\n```\n![图片说明](https://img-ask.csdn.net/upload/201811/04/1541340739_340119.gif)\n\n如果多人一样,但是都有误差,也平分,那么\nint i = 0;\nwhile (guess[ordered[i++]] == award) maxp++;\n修改为\nint i = 1;\nwhile (guess[ordered[i++]] == guess[0]) maxp++;\n\n`如果问题得到解决,请点我回答左上角的采纳,谢谢`\n", + "tag_name": "java", + "java": "import java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Arrays;\nclass Q707984 {\n\tpublic static void main(String[] args) {\n\t\tint award = 100;\n\t\tString[] people = { \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\" };\n\t\tInteger[] guess = { 75, 70, 80, 120, 100, 110, 100, 45 };\n\t\tInteger[] ordered = new Integer[people.length];\n\t\tfor (int i = 0; i < ordered.length; i++)\n\t\t\tordered[i] = i;\n\t\tArrays.sort(ordered, new Comparator() {\n\t\t\t@Override\n\t\t\tpublic int compare(Integer a, Integer b) {\n\t\t\t\tint x = guess[a] - award > 0 ? guess[a] - award : award - guess[a];\n\t\t\t\tint y = guess[b] - award > 0 ? guess[b] - award : award - guess[b];\n\t\t\t\treturn x - y;\n\t\t\t}\n\t\t});\n\t\tint maxp = 0;\n\t\tint i = 0;\n\t\twhile (guess[ordered[i++]] == award)\n\t\t\tmaxp++;\n\t\tif (maxp <= 1)\n\t\t\tSystem.out.println(people[ordered[0]] + \"一人得奖\" + award + \"元。\");\n\t\telse {\n\t\t\tfor (i = 0; i < maxp; i++)\n\t\t\t\tSystem.out.print(people[ordered[i]] + \" \");\n\t\t\tSystem.out.println(\"共同得奖\" + award / (float) (maxp) + \"元。\");\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469975", + "status": 1, + "keywords": "算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/18.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/19.json b/data_backup/java_code_json/19.json new file mode 100644 index 000000000..f739e73f7 --- /dev/null +++ b/data_backup/java_code_json/19.json @@ -0,0 +1,17 @@ +{ + "question_id": 159444, + "question_title": "自动获取计算机的ip地址和mac地址", + "question_content": "自动获取计算机的ip地址和mac地址", + "difficulty": "简单", + "answer_id": 24936, + "answer_content": "\n\n```\n public static String getMacAddressIP(String remotePcIP) {\n String str = \"\";\n String macAddress = \"\";\n try {\n Process pp = Runtime.getRuntime().exec(\"nbtstat -A \" + remotePcIP);\n InputStreamReader ir = new InputStreamReader(pp.getInputStream());\n LineNumberReader input = new LineNumberReader(ir);\n for (int i = 1; i < 100; i++) {\n str = input.readLine();\n if (str != null) {\n if (str.indexOf(\"MAC Address\") > 1) {\n macAddress = str.substring(\n str.indexOf(\"MAC Address\") + 14, str.length());\n break;\n }\n }\n }\n } catch (IOException ex) {\n }\n return macAddress;\n }\n```\n\n", + "tag_name": "java", + "java": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.LineNumberReader;\nclass java_15944{\n public static String getMacAddressIP(String remotePcIP) {\n String str = \"\";\n String macAddress = \"\";\n try {\n Process pp = Runtime.getRuntime().exec(\"nbtstat -A \" + remotePcIP);\n InputStreamReader ir = new InputStreamReader(pp.getInputStream());\n LineNumberReader input = new LineNumberReader(ir);\n for (int i = 1; i < 100; i++) {\n\tstr = input.readLine();\n\tif (str != null) {\n\t if (str.indexOf(\"MAC Address\") > 1) {\n\t macAddress = str.substring(\n\t\tstr.indexOf(\"MAC Address\") + 14, str.length());\n\t break;\n\t }\n\t}\n }\n } catch (IOException ex) {\n }\n return macAddress;\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600469874", + "status": 0, + "keywords": "ip地址,mac地址", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/19.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/2.json b/data_backup/java_code_json/2.json new file mode 100644 index 000000000..d7f7fe9b7 --- /dev/null +++ b/data_backup/java_code_json/2.json @@ -0,0 +1,18 @@ +{ + "question_id": 7412958, + "question_title": "打印1000以内的所有素数,并从键盘输入一个正整数,判断是否为素数。", + "question_content": "

1、主类内至少两个方法,boolean prime(int p)方法和main()方法,prime方法判断参数p是否为素数。 \n2、1000以内的素数放入一个数组再打印。 \n3、单行风格,良好可读性,运行结果正确。

", + "difficulty": "简单", + "answer_id": 53364537, + "answer_content": "
\npublic class Main {\n    public static void main(String[] args) {\n        List<Integer> numList = new ArrayList<>();\n        for(int i= 2;i<=1000;i++){\n            for(int j=2;j<=i;j++){\n                if(i%j==0&&j!=i){\n                    break;\n                }else if(j==i){\n                    numList.add(i);\n                }\n            }\n        }\n        System.out.println("1000以内的素数");\n        for(Integer integer : numList){\n            System.out.print(integer+" ");\n        }\n        System.out.println();\n        Scanner scanner = new Scanner(System.in);\n        int i = scanner.nextInt();\n        function function = new function();\n        System.out.println(function.prime(i));\n    }\n\n}\nclass function{\n    public boolean prime(int p){\n        for(int i = 2;i<=(p/2);i++){\n            if(p%i==0&&p!=i){\n                return false;\n            }\n        }\n        return true;\n    }\n}
\n\n

 

", + "tag_name": "java", + "java": "import java.util.*;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tList numList = new ArrayList<>();\n\t\tfor(int i= 2;i<=1000;i++){\n\t\t\tfor(int j=2;j<=i;j++){\n\t\t\t\tif(i%j==0&&j!=i){\n\t\t\t\t\tbreak;\n\t\t\t\t}else if(j==i){\n\t\t\t\t\tnumList.add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"1000以内的素数\");\n\t\tfor(Integer integer : numList){\n\t\t\tSystem.out.print(integer+\" \");\n\t\t}\n\t\tSystem.out.println();\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint i = scanner.nextInt();\n\t\tfunction function = new function();\n\t\tSystem.out.println(function.prime(i));\n\t}\n}\nclass function{\n\tpublic boolean prime(int p){\n\t\tfor(int i = 2;i<=(p/2);i++){\n\t\t\tif(p%i==0&&p!=i){\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469870", + "status": 1, + "keywords": "算法高阶,数论算法,素数的测试,算法问题选编", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/2.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/20.json b/data_backup/java_code_json/20.json new file mode 100644 index 000000000..7b731dad9 --- /dev/null +++ b/data_backup/java_code_json/20.json @@ -0,0 +1,18 @@ +{ + "question_id": 7453032, + "question_title": "按要求编写User类", + "question_content": "

编写User类,要求具有私有属性:用户名(account)和密码(password);具有行为:密码的setPassword()和getPassword()方法。编写一个测试类,要求实例化一个User用户,并且使用构造方法对其进行初始化,输出用户密码信息。

", + "difficulty": "简单", + "answer_id": 53435568, + "answer_content": "

例子代码:

\n\n
\npublic class User {\n    private String account;\n    private String password;\n\n    public String getAccount() {\n        return account;\n    }\n\n    public void setAccount(String account) {\n        this.account = account;\n    }\n\n    public String getPassword() {\n        return password;\n    }\n\n    public void setPassword(String password) {\n        this.password = password;\n    }\n\n    public User() {\n    }\n\n    public User(String account, String password) {\n        this.account = account;\n        this.password = password;\n    }\n    //登录方法\n    public void login(String account,String password){\n        if(account=="admin"&&password=="123456"){\n            System.out.println("登录成功");\n        }else {\n            System.out.println("账号密码不对");\n        }\n    }\n\n    public static void main(String[] args) {\n        User user=new User();\n        user.login("admin","123456");\n    }\n}\n
\n\n

运行结果如图:

\n\n

\"\"

\n", + "tag_name": "java", + "java": "public class User {\n\tprivate String account;\n\tprivate String password;\n\tpublic String getAccount() {\n\t\treturn account;\n\t}\n\tpublic void setAccount(String account) {\n\t\tthis.account = account;\n\t}\n\tpublic String getPassword() {\n\t\treturn password;\n\t}\n\tpublic void setPassword(String password) {\n\t\tthis.password = password;\n\t}\n\tpublic User() {\n\t}\n\tpublic User(String account, String password) {\n\t\tthis.account = account;\n\t\tthis.password = password;\n\t}\n\tpublic void login(String account, String password) {\n\t\tif (account == \"admin\" && password == \"123456\") {\n\t\t\tSystem.out.println(\"登录成功\");\n\t\t} else {\n\t\t\tSystem.out.println(\"账号密码不对\");\n\t\t}\n\t}\n\tpublic static void main(String[] args) {\n\t\tUser user = new User();\n\t\tuser.login(\"admin\", \"123456\");\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470285", + "status": 0, + "keywords": "算法高阶,基本方法,高级数据结构,van Emde Boas树", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/20.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/21.json b/data_backup/java_code_json/21.json new file mode 100644 index 000000000..b09ffcadf --- /dev/null +++ b/data_backup/java_code_json/21.json @@ -0,0 +1,17 @@ +{ + "question_id": 214128, + "question_title": "素数判断", + "question_content": "判断任意整数是否是素数", + "difficulty": "简单", + "answer_id": 157880, + "answer_content": "public class Num{\npublic static void main(String args[]){\n int m;\n boolean tag=true;\n System.out.print(\"Please enter a num:\");\n try{\n m=(int)System.in.read();\n for(int i=m-1;i>1;i--)\n if(m%i==0)\n tag=false;\n if(tag==true)\n System.out.println(m+\"is a sushu\");\n }catch(IOExceptimn e){}\n}\n}", + "tag_name": "java", + "java": "import java.io.IOException;\npublic class Num{\npublic static void main(String args[]){\n int m;\n boolean tag=true;\n System.out.print(\"Please enter a num:\");\n try{\n\tm=(int)System.in.read();\n\tfor(int i=m-1;i>1;i--)\n\t if(m%i==0)\n\t\t tag=false;\n\tif(tag==true)\n\t System.out.println(m+\"is a sushu\");\n }catch(IOException e){}\n}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470286", + "status": 0, + "keywords": "算法高阶,数论算法,素数的测试,算法问题选编", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/21.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/22.json b/data_backup/java_code_json/22.json new file mode 100644 index 000000000..e775d816a --- /dev/null +++ b/data_backup/java_code_json/22.json @@ -0,0 +1,18 @@ +{ + "question_id": 7436836, + "question_title": "数组元素统计", + "question_content": "

定义一个长度为5的数组arr1,用于存放5个1~9的随机整数(范围包含1和9),再定义一个长度为2的数组arr2,统计arr1中的元素对2求余等于0的个数,保存到arr2[0], 统计arr1中的元素对3求余等于0的个数,保存到arr2[1],在控制台打印输出arr2的所有元素

", + "difficulty": "简单", + "answer_id": 53409011, + "answer_content": "
\npackage com.auskat.demo.cc;\n\nimport java.util.Random;\n\n/**\n * 类文件: RandomTest\n * <p>\n * <p>\n * 类描述:\n * <p>\n * 作     者: AusKa_T\n * <p>\n * 日     期: 2021/5/27 0027\n * <p>\n * 时     间: 13:29\n * <p>\n */\npublic class RandomTest {\n\n    public static void main(String[] args) {\n\n        int arr1[] = new int[5];\n        for (int i = 0; i < arr1.length; i++) {\n            arr1[i] =  new Random().nextInt(9) + 1;\n        }\n\n\n        int i2 = 0;\n        int j3 = 0;\n        for (int i = 0; i < arr1.length; i++) {\n            if(arr1[i] % 2 == 0) {\n                i2++;\n            }\n            if(arr1[i] % 3 == 0) {\n                j3++;\n            }\n        }\n\n        int arr2[] = new int[2];\n        arr2[0] = i2;\n        arr2[1] = j3;\n\n        for (int i = 0; i < arr2.length; i++) {\n            System.out.println(arr2[i]);\n        }\n\n    }\n}\n
\n\n

 

\n", + "tag_name": "java", + "java": "package com.auskat.demo.cc;\nimport java.util.Random;\npublic class RandomTest {\n\tpublic static void main(String[] args) {\n\t\tint arr1[] = new int[5];\n\t\tfor (int i = 0; i < arr1.length; i++) {\n\t\t\tarr1[i] = new Random().nextInt(9) + 1;\n\t\t}\n\t\tint i2 = 0;\n\t\tint j3 = 0;\n\t\tfor (int i = 0; i < arr1.length; i++) {\n\t\t\tif (arr1[i] % 2 == 0) {\n\t\t\t\ti2++;\n\t\t\t}\n\t\t\tif (arr1[i] % 3 == 0) {\n\t\t\t\tj3++;\n\t\t\t}\n\t\t}\n\t\tint arr2[] = new int[2];\n\t\tarr2[0] = i2;\n\t\tarr2[1] = j3;\n\t\tfor (int i = 0; i < arr2.length; i++) {\n\t\t\tSystem.out.println(arr2[i]);\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469875", + "status": 1, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/22.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/23.json b/data_backup/java_code_json/23.json new file mode 100644 index 000000000..cf57fb878 --- /dev/null +++ b/data_backup/java_code_json/23.json @@ -0,0 +1,18 @@ +{ + "question_id": 159655, + "question_title": "买蛋", + "question_content": "100元怎么买100个蛋,鸡蛋1毛一个,鸭蛋3元一个,鹅蛋6元一个", + "difficulty": "简单", + "answer_id": 25451, + "answer_content": "```\n public class Egg{\n\tpublic static void main(String[] args){\n\t\tint chicken=0,duck=0,goose=0;\n\t\tfor(int i=0;i<100;i++){\n\t\t\tchicken = i;\n\t\t\t\tfor(int j=0;j<100;j++){\n\t\t\t\t\tduck = j;\n\t\t\t\t\tgoose = 100-duck-chicken;\n\t\t\t\t\tif(chicken+duck*30+goose*60==1000&&chicken>0&&duck>0&&goose>0){\t\n\t\t\t\t\t\tSystem.out.println(\"鸡:\"+chicken+\" 鸭:\"+duck+\" 鹅:\"+goose);\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t}\n\t\t}\t\t\t\t\n\t}\t\n}\n```\n\n", + "tag_name": "java", + "java": "public class Egg {\n\tpublic static void main(String[] args) {\n\t\tint chicken = 0, duck = 0, goose = 0;\n\t\tfor (int i = 0; i < 100; i++) {\n\t\t\tchicken = i;\n\t\t\tfor (int j = 0; j < 100; j++) {\n\t\t\t\tduck = j;\n\t\t\t\tgoose = 100 - duck - chicken;\n\t\t\t\tif (chicken + duck * 30 + goose * 60 == 1000 && chicken > 0 && duck > 0 && goose > 0) {\n\t\t\t\t\tSystem.out.println(\"鸡:\" + chicken + \" 鸭:\" + duck + \" 鹅:\" + goose);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469876", + "status": 1, + "keywords": "算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/23.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/24.json b/data_backup/java_code_json/24.json new file mode 100644 index 000000000..9ac8eef28 --- /dev/null +++ b/data_backup/java_code_json/24.json @@ -0,0 +1,18 @@ +{ + "question_id": 714578, + "question_title": "计算阶乘的和", + "question_content": "编写程序计算1!+2!+3!+...+n!,并输出计算结果。(要求:n从键盘输入,0<=n<=50,如果输入的n值不在此范围,提示再次输入)", + "difficulty": "简单", + "answer_id": 706569, + "answer_content": "`如果问题得到解决,请点我回答左上角的采纳,谢谢`\n\n```\n/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\nclass Ideone\n{\n\tpublic static double p(int x)\n\t{\n\t\tdouble r = 1.0;\n\t\tfor (int i = 2; i <= x; i++) r *= i;\n\t\treturn r;\n\t}\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tif (n > 50 || n < 0)\n\t\t{\n\t\t\tSystem.out.println(\"不在范围!\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdouble d = 0;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\td += p(i);\n\t\t\tSystem.out.println(\"结果=\" + d);\n\t\t}\n\t}\n}\n```\n输入4\n输出结果=33.0\n在线验证\nhttps://ideone.com/ylntIF\n", + "tag_name": "java", + "java": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nclass Ideone {\n\tpublic static double p(int x) {\n\t\tdouble r = 1.0;\n\t\tfor (int i = 2; i <= x; i++)\n\t\t\tr *= i;\n\t\treturn r;\n\t}\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tif (n > 50 || n < 0) {\n\t\t\tSystem.out.println(\"不在范围!\");\n\t\t} else {\n\t\t\tdouble d = 0;\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\td += p(i);\n\t\t\tSystem.out.println(\"结果=\" + d);\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469976", + "status": 1, + "keywords": "算法高阶,计算几何学,算法问题选编", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/24.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/25.json b/data_backup/java_code_json/25.json new file mode 100644 index 000000000..11bf73e44 --- /dev/null +++ b/data_backup/java_code_json/25.json @@ -0,0 +1,18 @@ +{ + "question_id": 234859, + "question_title": "用0到9生成十位数的所有排列组合", + "question_content": "用 0到9 生成 十位数的所有排列组合,数字0不能在第一个,这个生成的十位数,不能有重复的数字。\n", + "difficulty": "简单", + "answer_id": 212594, + "answer_content": "\n\n```\n public static void main(String[] args) {\n\t\tString str[] = { \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\" };\n\t\tpermutation(str, 0, str.length);\n\t}\n\n\tstatic void swap(String[] str, int start, int end) {\n\t\tString tmep = str[start];\n\t\tstr[start] = str[end];\n\t\tstr[end] = tmep;\n\t}\n\n\tstatic void permutation(String[] str, int start, int end) {\n\n\t\tif (start == end - 1) {\n\t\t\tfor (int i = 0; i < end; i++) {\n\t\t\t\tSystem.out.print(str[i]);\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t} else {\n\n\t\t\tfor (int i = start; i < end; i++) {\n\t\t\t\tif (i == 0 && str[0].equals(\"0\"))\n\t\t\t\t\tcontinue;\n\t\t\t\tswap(str, start, i);\n\t\t\t\tpermutation(str, start + 1, end);\n\n\t\t\t\tswap(str, start, i);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n", + "tag_name": "java", + "java": "class java_234859 {\n public static void main(String[] args) {\n\t String str[] = { \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\" };\n\t permutation(str, 0, str.length);\n }\n static void swap(String[] str, int start, int end) {\n\t String tmep = str[start];\n\t str[start] = str[end];\n\t str[end] = tmep;\n }\n static void permutation(String[] str, int start, int end) {\n\t if (start == end - 1) {\n\t\t for (int i = 0; i < end; i++) {\n\t\t\tSystem.out.print(str[i]);\n\t\t }\n\t\t System.out.println();\n\t } else {\n\t\t for (int i = start; i < end; i++) {\n\t\t\tif (i == 0 && str[0].equals(\"0\"))\n\t\t\t continue;\n\t\t\tswap(str, start, i);\n\t\t\tpermutation(str, start + 1, end);\n\t\t\tswap(str, start, i);\n\t\t }\n\t }\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600470287", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/25.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/26.json b/data_backup/java_code_json/26.json new file mode 100644 index 000000000..c01b135b9 --- /dev/null +++ b/data_backup/java_code_json/26.json @@ -0,0 +1,17 @@ +{ + "question_id": 1056822, + "question_title": "统计022022的个数", + "question_content": "一组数里面是0,0,0,1,0,0,2,2,0,2,2,0,0,3,0,0,0,0 (0,2,2,0,2,2就算一个室早三联)如果022022是连续出现的话也只算一个比如022022022022这样也只算一个不连续的022022才++,统计022022的个数,", + "difficulty": "中等", + "answer_id": 1253873, + "answer_content": "\n```\npackage com.lee.study;\n\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class Study20 {\n public static int getAmount(int[] numbers) {\n\n Pattern p = Pattern.compile(\"(?=0; i--)\n System.out.print(try1[i]);\n }\n}\n```\n**如果对您有帮助,请点击采纳答案好吗,谢谢~~**\n", + "tag_name": "java", + "java": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nclass ReverseString {\n\tpublic static void main(String[] args) {\n\t\tString input = \"abcd1234\";\n\t\tchar[] try1 = input.toCharArray();\n\t\tfor (int i = try1.length - 1; i >= 0; i--)\n\t\t\tSystem.out.print(try1[i]);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470192", + "status": 1, + "keywords": "排序", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/27.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/28.json b/data_backup/java_code_json/28.json new file mode 100644 index 000000000..39b3afa2a --- /dev/null +++ b/data_backup/java_code_json/28.json @@ -0,0 +1,18 @@ +{ + "question_id": 7451564, + "question_title": "判断偶数", + "question_content": "

判断偶数。定义一个长度为10的整型数组,随机产生10个100之内的整数,然后判断这个数组中有几个偶数,并输出偶数个数及所有偶数。

", + "difficulty": "简单", + "answer_id": 53432874, + "answer_content": "

我给你写下,稍等。

\n\n
\npublic static void main(String args[]){\n        int arr[] = new int[10];\n        int count = 0;\n        System.out.println("随机产生10个整数:");\n        for(int i = 0; i < 10; i++){\n            arr[i] =(int)(Math.random() * 100 + 1);\n        }\n        for(int i = 0; i < arr.length; i++){\n            if(i % 2 == 0) {\n                System.out.println(i);\n                count++;\n            }\n        }\n        System.out.println("偶数个数:" + count);\n    }
\n\n

 

\n", + "tag_name": "java", + "java": "class java_7451564 {\n\tpublic static void main(String args[]) {\n\t\tint arr[] = new int[10];\n\t\tint count = 0;\n\t\tSystem.out.println(\"随机产生10个整数:\");\n\t\tfor (int i = 0; i < 10; i++) {\n\t\t\tarr[i] = (int) (Math.random() * 100 + 1);\n\t\t}\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tif (arr[i] % 2 == 0) {\n\t\t\t\tSystem.out.println(arr[i]);\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"偶数个数:\" + count);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470288", + "status": 0, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/28.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/29.json b/data_backup/java_code_json/29.json new file mode 100644 index 000000000..1d444c531 --- /dev/null +++ b/data_backup/java_code_json/29.json @@ -0,0 +1,18 @@ +{ + "question_id": 7445932, + "question_title": "按以下要求实现程序功能", + "question_content": "

从键盘输入5个整型值\n1)按从大到小顺序排序方法;\n2)计算这些数的平均值的方法;\n3)在主方法中调用这些方法,并输出相应的值。

", + "difficulty": "简单", + "answer_id": 53425337, + "answer_content": "
\n    public static void main(String[] args) {\n        List<Integer> list = new ArrayList<>();\n        Scanner scanner = new Scanner(System.in);\n        for (int a = 1; a < 6; a++){\n            System.out.print("请输入第 " + a + " 个值:");\n            list.add(scanner.nextInt());\n        }\n        System.out.println(descending(list));\n        System.out.println(getAvg(list));\n\n    }\n    // 降序\n    public static List<Integer> descending(List<Integer> list){\n        list.sort(Collections.reverseOrder());\n        return list;\n    }\n    // 平均值\n    public static Double getAvg(List<Integer> list){\n        return list.stream().mapToInt(Integer::new).average().getAsDouble();\n    }
\n", + "tag_name": "java", + "java": "import java.util.*;\nclass java_7445932 {\n\tpublic static void main(String[] args) {\n\t\tList list = new ArrayList<>();\n\t\tScanner scanner = new Scanner(System.in);\n\t\tfor (int a = 1; a < 6; a++) {\n\t\t\tSystem.out.print(\"请输入第 \" + a + \" 个值:\");\n\t\t\tlist.add(scanner.nextInt());\n\t\t}\n\t\tSystem.out.println(descending(list));\n\t\tSystem.out.println(getAvg(list));\n\t}\n\tpublic static List descending(List list) {\n\t\tlist.sort(Collections.reverseOrder());\n\t\treturn list;\n\t}\n\tpublic static Double getAvg(List list) {\n\t\treturn list.stream().mapToInt(Integer::new).average().getAsDouble();\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469877", + "status": 1, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/29.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/3.json b/data_backup/java_code_json/3.json new file mode 100644 index 000000000..26324d387 --- /dev/null +++ b/data_backup/java_code_json/3.json @@ -0,0 +1,17 @@ +{ + "question_id": 357568, + "question_title": "计算距离下个生日还有多少天", + "question_content": "怎么写出出生年月日来计算距离下个生日还有多少天的方法?\n出生年月日的格式是yyyy-MM-dd。\n返回值为String类型", + "difficulty": "简单", + "answer_id": 374359, + "answer_content": "// 用来计算两个日期之间相差的毫秒数\n public static void test(String date1,String date2) throws ParseException\n {\n DateFormat df = DateFormat.getDateInstance();\n df= new SimpleDateFormat(\"yyyy-MM-dd\");\n \n Date date_1 = df.parse(date1);\n Date date_2 = df.parse(date2);\n \n long time1 = date_1.getTime();\n long time2 = date_2.getTime();\n long time3 = Math.abs(time1-time2);\n \n int day = getDay(time3);\n System.out.println(\"两日期相隔\"+day+\"天\");\n }\n//将两个日期之间的毫秒数换算成天数\n private static int getDay(long time)\n {\n int day = (int)(time/1000/60/60/24);\n return day;\n }", + "tag_name": "java", + "java": "import java.sql.Date;\nimport java.text.DateFormat;\nimport java.text.ParseException;\nimport java.text.SimpleDateFormat;\nclass java_357568{\n public static void test(String date1,String date2) throws ParseException\n {\n DateFormat df = DateFormat.getDateInstance();\n df= new SimpleDateFormat(\"yyyy-MM-dd\");\n Date date_1 = (Date) df.parse(date1);\n Date date_2 = (Date) df.parse(date2);\n long time1 = date_1.getTime();\n long time2 = date_2.getTime();\n long time3 = Math.abs(time1-time2);\n int day = getDay(time3);\n\t System.out.println(\"两日期相隔\"+day+\"天\");\n }\n private static int getDay(long time)\n {\n int day = (int)(time/1000/60/60/24);\n return day;\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600470185", + "status": 0, + "keywords": "算法初阶,基础知识,生日悖论,概率分析和随机算法,概率分析和指示器随机变量的进一步使用", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/3.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/30.json b/data_backup/java_code_json/30.json new file mode 100644 index 000000000..91de4ff5e --- /dev/null +++ b/data_backup/java_code_json/30.json @@ -0,0 +1,18 @@ +{ + "question_id": 701664, + "question_title": "外出采摘的日本人", + "question_content": "二战后的某一天,N个日本人来到了一个山洞休息,为了派出一个日本人去外面充满危险的丛林中采摘食物,他们设置如下游戏产生外出采摘的人: \n1、首先,所有参加游戏的日本人按顺序编号为1、2、3…N; \n2、接下来每个日本人心里产生一个数字,这个数字称为序号为 N的人的密码P; \n3、所有参加游戏的人按照编号站成一个圈,长老为游戏设置初始密码K,从编号为 1的人开始报数,报到 K的人退出队伍,然后将自己心中的密码P说出来,由下一个人继续从 1开始报数,报到P的人退出队伍,以此类推; \n4、当队伍中剩下一个人的时候,这个人就是今天要出去采摘的日本人,他可能回不来了! \n请各位同学设计程序并使用Java语言实现改程序,在用户输入了人数N、每个人的密码P和初始密码K的情况下,自动完成上面的选择过程,输出先后离开队伍的人的序号序列,最后输出要去采摘的日本人,输出他的编号。", + "difficulty": "中等", + "answer_id": 591605, + "answer_content": "```\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class JosephCircle {\n\n public int newJoseph(int n, int[] p, int k) {\n List num = new ArrayList();\n for( int i = 0; i < n; i++ ) num.add(i);\n\n int t = k, index = 0;\n for( int i = 0; i < n - 1; i++ ) {\n index = ( index + t ) % num.size();\n num.remove(index);\n t = p[index];\n if(index == num.size()) index=0;\n }\n return num.get(0)+1;\n }\n\n public int oldJoseph(int n, int k){\n int w = 0;\n for( int i = 2; i <= n; i++ ){\n w = (w+k)%i;\n }\n return w;\n }\n\n public static void main(String[] args) {\n JosephCircle jc = new JosephCircle();\n Scanner scan = new Scanner(System.in);\n\n int n,k;\n int[] p = new int[100];\n System.out.print(\"Enter N = \");n = scan.nextInt();\n System.out.print(\"Enter P[] = \");\n for(int i = 0; i < n; i++){\n p[i] = scan.nextInt();\n }\n System.out.print(\"Enter K = \");k = scan.nextInt();\n System.out.println();\n System.out.println(\"Survivor is No.\" + jc.newJoseph(n,p,k));\n }\n}\n\n```\n\n", + "tag_name": "java", + "java": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\npublic class JosephCircle {\n\tpublic int newJoseph(int n, int[] p, int k) {\n\t\tList num = new ArrayList();\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tnum.add(i);\n\t\tint t = k, index = 0;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tindex = (index + t) % num.size();\n\t\t\tnum.remove(index);\n\t\t\tt = p[index];\n\t\t\tif (index == num.size())\n\t\t\t\tindex = 0;\n\t\t}\n\t\treturn num.get(0) + 1;\n\t}\n\tpublic int oldJoseph(int n, int k) {\n\t\tint w = 0;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tw = (w + k) % i;\n\t\t}\n\t\treturn w;\n\t}\n\tpublic static void main(String[] args) {\n\t\tJosephCircle jc = new JosephCircle();\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n, k;\n\t\tint[] p = new int[100];\n\t\tSystem.out.print(\"Enter N = \");\n\t\tn = scan.nextInt();\n\t\tSystem.out.print(\"Enter P[] = \");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tp[i] = scan.nextInt();\n\t\t}\n\t\tSystem.out.print(\"Enter K = \");\n\t\tk = scan.nextInt();\n\t\tSystem.out.println();\n\t\tSystem.out.println(\"Survivor is No.\" + jc.newJoseph(n, p, k));\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469977", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量,最坏情况为线性时间的选择算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/30.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/31.json b/data_backup/java_code_json/31.json new file mode 100644 index 000000000..232a04843 --- /dev/null +++ b/data_backup/java_code_json/31.json @@ -0,0 +1,18 @@ +{ + "question_id": 1058612, + "question_title": "求素数", + "question_content": "求1-100内的素数", + "difficulty": "简单", + "answer_id": 1255940, + "answer_content": "如楼上所说到平方根即可,性能更好,可以参考下:https://blog.csdn.net/qq_42889294/article/details/86578832\n\n```\npublic static void main(String[] args){\n\n for(int i=0;i<100;i++) {\n checkPrime(i);\n }\n \n }\n\n private static void checkPrime(int x){\n boolean isPrime = true;\n if(x ==1 || x %2 ==0 && x !=2 )\n {\n isPrime = false;\n }\n else\n {\n for( int i =3; i< Math.sqrt(x); i+=2)\n {\n if( x % i == 0)\n {\n isPrime = false;\n break;\n }\n }\n }\n if( isPrime)\n {\n System.out.println(x +\"是素数\");\n }\n else\n {\n System.out.println(x+ \"不是素数\");\n }\n }\n\n\n```\n以下是输入20以内返回的结果:\n![图片说明](https://img-ask.csdn.net/upload/202003/14/1584172080_762422.jpg)\n", + "tag_name": "java", + "java": "public static void main(String[] args){\n\t\tfor(int i=0;i<100;i++) {\n\t\t\tcheckPrime(i);\n\t\t}\n\t}\n\tprivate static void checkPrime(int x){\n\t\tboolean isPrime = true;\n\t\tif(x ==1 || x %2 ==0 && x !=2 )\n\t\t{\n\t\t\tisPrime = false;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor( int i =3; i< Math.sqrt(x); i+=2)\n\t\t\t{\n\t\t\t\tif( x % i == 0)\n\t\t\t\t{\n\t\t\t\t\tisPrime = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif( isPrime)\n\t\t{\n\t\t\tSystem.out.println(x +\"是素数\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(x+ \"不是素数\");\n\t\t}\n\t}", + "topic_link": "https://bbs.csdn.net/topics/600470193", + "status": 1, + "keywords": "算法高阶,数论算法,素数的测试,算法问题选编", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/31.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/32.json b/data_backup/java_code_json/32.json new file mode 100644 index 000000000..c0aba4444 --- /dev/null +++ b/data_backup/java_code_json/32.json @@ -0,0 +1,18 @@ +{ + "question_id": 7431662, + "question_title": "定义一个类Generator", + "question_content": "

定义一个类 Generator(生成器类),它可以在每次调用其 next()方法时,产生由你 最喜欢的电影(如 Snow White 或 Star Wars)的字符构成的名字(作为 String 对象)。在字 符列表中的电影名用完之后,循环到这个字符列表的开始处。使用这个生成器来填充数组、 ArrayList、LinkedList、HashSet,然后打印每一个容器。

", + "difficulty": "简单", + "answer_id": 53400496, + "answer_content": "
\nimport java.util.*;\npublic class MovieGenerator {\n    private String[] movies = new String[] { "SS", "DD", "HH", "FF", "XX", "ZZ" };\n    private int i = 0;\n    public String next() {\n        return movies[i++ % movies.length];\n    }\n    public String[] getMovies() {\n        return movies;\n    }\n    public Collection<String> fill(Collection<String> collection) {\n        for (int i = 0; i < 8; i++) {\n        collection.add(next());\n        }\n        return collection;\n    }\n    public static void main(String[] args) {\n        MovieGenerator generator = new MovieGenerator();\n        System.out.println(Arrays.toString(generator.getMovies()));\n        System.out.println(generator.fill(new ArrayList<String>()));\n        System.out.println(generator.fill(new LinkedList<String>()));\n        System.out.println(generator.fill(new HashSet<String>()));\n    }\n}
\n\n

 

\n", + "tag_name": "java", + "java": "import java.util.*;\npublic class MovieGenerator {\n\tprivate String[] movies = new String[] { \"SS\", \"DD\", \"HH\", \"FF\", \"XX\", \"ZZ\" };\n\tprivate int i = 0;\n\tpublic String next() {\n\t\treturn movies[i++ % movies.length];\n\t}\n\tpublic String[] getMovies() {\n\t\treturn movies;\n\t}\n\tpublic Collection fill(Collection collection) {\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tcollection.add(next());\n\t\t}\n\t\treturn collection;\n\t}\n\tpublic static void main(String[] args) {\n\t\tMovieGenerator generator = new MovieGenerator();\n\t\tSystem.out.println(Arrays.toString(generator.getMovies()));\n\t\tSystem.out.println(generator.fill(new ArrayList()));\n\t\tSystem.out.println(generator.fill(new LinkedList()));\n\t\tSystem.out.println(generator.fill(new HashSet()));\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469978", + "status": 1, + "keywords": "散列表,散列表,算法中阶,数据结构", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/32.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/33.json b/data_backup/java_code_json/33.json new file mode 100644 index 000000000..4a4e76251 --- /dev/null +++ b/data_backup/java_code_json/33.json @@ -0,0 +1,18 @@ +{ + "question_id": 243824, + "question_title": "字符串统计", + "question_content": "编写一个程序,对于输入的一段英语文本,可以统计:\n1、该文本中有多少英语单词;\n2、该文本中有多少不同的英语单词。\n如,输入 I am a good student. I am in Zhengzhou.\n则可以统计出有9个英语单词、7个不同的英语单词。", + "difficulty": "简单", + "answer_id": 232730, + "answer_content": "首先,需要对输入信息进行处理,去掉输入的标点符号,并以空格替换,需要用正则表达式,进行全部替换;\n其次,就是对输入单词进行统计,使用字符串的分割函数split(\" \"),以空格分割;\n最后,就是遍历分割结果,进行统计,用Map,以单词为key,出现次数为value。\n实例代码如下:\n```\n import java.util.HashMap;\nimport java.util.Map;\n\npublic class Tee {\n\t/**\n\t * 正则去除所有的英文标点符号\n\t */\n\tpublic static String formatInput(String input) {\n\t\tif (input == null) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn input.replaceAll(\"[.|;|\\\\?]\", \" \");\n\t}\n\n\tpublic static Map countWords(String input) {\n\t\tMap result = new HashMap();\n\t\tif (input == null || input.length() == 0) {\n\t\t\treturn result;\n\t\t}\n\t\t// 用字符串的分割函数\n\t\tString[] split = input.split(\" \");\n\t\tif (split == null || split.length == 0) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// 统计存入Map,word为key,出现次数为value\n\t\tfor (String value : split) {\n\t\t\tif (result.containsKey(value)) {\n\t\t\t\t// 出现过,直接累计+1\n\t\t\t\tresult.put(value, result.get(value) + 1);\n\t\t\t} else {\n\t\t\t\t// 没出现过存入\n\t\t\t\tresult.put(value, 1);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tString value = \"I am a good student.I am in Zhengzhou.Ha?\";\n\t\tString format = formatInput(value);\n\t\tSystem.out.println(format);\n\t\tMap r = countWords(format);\n\t\tSystem.out.println(r.toString());\n\t}\n}\n```\n\n", + "tag_name": "java", + "java": "import java.util.HashMap;\nimport java.util.Map;\npublic class Tee {\n\tpublic static String formatInput(String input) {\n\t\tif (input == null) {\n\t\t\treturn null;\n\t\t}\n\t\treturn input.replaceAll(\"[.|;|\\\\?]\", \" \");\n\t}\n\tpublic static Map countWords(String input) {\n\t\tMap result = new HashMap();\n\t\tif (input == null || input.length() == 0) {\n\t\t\treturn result;\n\t\t}\n\t\tString[] split = input.split(\" \");\n\t\tif (split == null || split.length == 0) {\n\t\t\treturn result;\n\t\t}\n\t\tfor (String value : split) {\n\t\t\tif (result.containsKey(value)) {\n\t\t\t\tresult.put(value, result.get(value) + 1);\n\t\t\t} else {\n\t\t\t\tresult.put(value, 1);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\tpublic static void main(String[] args) {\n\t\tString value = \"I am a good student.I am in Zhengzhou.Ha?\";\n\t\tString format = formatInput(value);\n\t\tSystem.out.println(format);\n\t\tMap r = countWords(format);\n\t\tSystem.out.println(r.toString());\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469878", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/33.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/34.json b/data_backup/java_code_json/34.json new file mode 100644 index 000000000..9b000293b --- /dev/null +++ b/data_backup/java_code_json/34.json @@ -0,0 +1,18 @@ +{ + "question_id": 7455237, + "question_title": "数组排序", + "question_content": "

编写一个JavaApplication程序,将随机生成的无序数组使用冒泡排序,将这个混乱的数组变成一个从小到大排列的有序的数组并输出。

", + "difficulty": "简单", + "answer_id": 53438050, + "answer_content": "

其实就是个冒泡排序呗

\n\n
\nclass demo_sort {\n        public static void main(String[] args) {\n            //冒泡排序算法\n            int[] numbers=new int[]{1,5,8,2,3,9,4};\n            //需进行length-1次冒泡\n            for(int i=0;i<numbers.length-1;i++)\n            {\n                for(int j=0;j<numbers.length-1-i;j++)\n                {\n                    if(numbers[j]>numbers[j+1])\n                    {\n                        int temp=numbers[j];\n                        numbers[j]=numbers[j+1];\n                        numbers[j+1]=temp;\n                    }\n                }\n            }\n            System.out.println("从小到大排序后的结果是:");\n            for(int i=0;i<numbers.length;i++)\n                System.out.print(numbers[i]+" ");\n        }\n    }
\n\n

 

\n", + "tag_name": "java", + "java": "class demo_sort {\n\tpublic static void main(String[] args) {\n\t\tint[] numbers = new int[] { 1, 5, 8, 2, 3, 9, 4 };\n\t\tfor (int i = 0; i < numbers.length - 1; i++) {\n\t\t\tfor (int j = 0; j < numbers.length - 1 - i; j++) {\n\t\t\t\tif (numbers[j] > numbers[j + 1]) {\n\t\t\t\t\tint temp = numbers[j];\n\t\t\t\t\tnumbers[j] = numbers[j + 1];\n\t\t\t\t\tnumbers[j + 1] = temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"从小到大排序后的结果是:\");\n\t\tfor (int i = 0; i < numbers.length; i++)\n\t\t\tSystem.out.print(numbers[i] + \" \");\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470289", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/34.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/35.json b/data_backup/java_code_json/35.json new file mode 100644 index 000000000..65af96ac2 --- /dev/null +++ b/data_backup/java_code_json/35.json @@ -0,0 +1,18 @@ +{ + "question_id": 717710, + "question_title": "单词反转", + "question_content": "随便输出一个字符串\nString str =\"45abc,+de==fg\";\n里面含有 abc,de,fg 三个单词\n怎么处理能让单词反转,其他顺序不变呢\n输出 “45cba,+ed==gf”;", + "difficulty": "中等", + "answer_id": 711099, + "answer_content": "\n```\npublic class HelloWorld {\n\tpublic static String revstr(String s)\n\t{\n\t\tchar[] ch = s.toCharArray();\n\t\tfor (int i = 0; i < ch.length; i++)\n\t\t{\n\t\t\tif ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z'))\n\t\t\t{\n\t\t\t\tint j = i + 1;\n\t\t\t\twhile (j < ch.length && ((ch[j] >= 'A' && ch[j] <= 'Z') || (ch[j] >= 'a' && ch[j] <= 'z'))) j++;\n\t\t\t\tj--;\n\t\t\t\tif (i != j)\n\t\t\t\t{\n\t\t\t\t\tfor (int k = i; k <= (j - i) / 2 + i; k++)\n\t\t\t\t\t{\n\t\t\t\t\t\t//System.out.println(\"i\" + i + \"j\" + j + \"k\" + k);\n\t\t\t\t\t\tchar temp = ch[k];\n\t\t\t\t\t\tch[k] = ch[j - k + i];\n\t\t\t\t\t\tch[j - k + i] = temp;\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti = j;\n\t\t\t}\n\t\t}\n\t\treturn new String(ch);\n\t}\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(revstr(\"45abc,+de==fg\"));\n\t}\n}\n```\n45cba,+ed==gf\n", + "tag_name": "java", + "java": "public class HelloWorld {\n\tpublic static String revstr(String s) {\n\t\tchar[] ch = s.toCharArray();\n\t\tfor (int i = 0; i < ch.length; i++) {\n\t\t\tif ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')) {\n\t\t\t\tint j = i + 1;\n\t\t\t\twhile (j < ch.length && ((ch[j] >= 'A' && ch[j] <= 'Z') || (ch[j] >= 'a' && ch[j] <= 'z')))\n\t\t\t\t\tj++;\n\t\t\t\tj--;\n\t\t\t\tif (i != j) {\n\t\t\t\t\tfor (int k = i; k <= (j - i) / 2 + i; k++) {\n\t\t\t\t\t\tchar temp = ch[k];\n\t\t\t\t\t\tch[k] = ch[j - k + i];\n\t\t\t\t\t\tch[j - k + i] = temp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti = j;\n\t\t\t}\n\t\t}\n\t\treturn new String(ch);\n\t}\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(revstr(\"45abc,+de==fg\"));\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469879", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/35.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/36.json b/data_backup/java_code_json/36.json new file mode 100644 index 000000000..e4b1ed7c9 --- /dev/null +++ b/data_backup/java_code_json/36.json @@ -0,0 +1,18 @@ +{ + "question_id": 1065837, + "question_title": "多线程问题", + "question_content": "1.程序中需要开启两个线程(线程1和线程2)\n2.线程1固定5秒钟执行一次\n3.线程2固定10秒钟执行一次\n4.开启程序如何做到线程1执行完成后再执行线程2并且在之后无论谁先执行都需等待对方执行完成后才可以开始执行\n", + "difficulty": "中等", + "answer_id": 1265160, + "answer_content": "两个线程在执行操作的时候共享同一把锁就可以保证先后顺序了,demo:\n\n```\npublic class TestThreadJoin {\n\tpublic static void main(String[] args) {\n\t\tfinal Object lock = new Object();\n\t\tRunnable r1 = ()->{\n\t\t\twhile(true) {\n\t\t\t\t// 执行时获取锁\n\t\t\t\tsynchronized(lock) {\n\t\t\t\t\tSystem.out.println(\"线程1执行。\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tThread.sleep(5000);\n\t\t\t\t} catch (InterruptedException e) {\n\t\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\n\t\tRunnable r2 = ()->{\n\t\t\twhile(true) {\n\t\t\t\t// 执行时获取锁\n\t\t\t\tsynchronized(lock) {\n\t\t\t\t\tSystem.out.println(\"线程2执行。\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tThread.sleep(10000);\n\t\t\t\t} catch (InterruptedException e) {\n\t\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t};\n\t\t\n\t\tnew Thread(r1).start();\n\t\tnew Thread(r2).start();\n\t}\n\n}\n```", + "tag_name": "java", + "java": "public class TestThreadJoin {\n\tpublic static void main(String[] args) {\n\t\tfinal Object lock = new Object();\n\t\tRunnable r1 = () -> {\n\t\t\twhile (true) {\n\t\t\t\tsynchronized (lock) {\n\t\t\t\t\tSystem.out.println(\"线程1执行。\");\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tThread.sleep(5000);\n\t\t\t\t} catch (InterruptedException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tRunnable r2 = () -> {\n\t\t\twhile (true) {\n\t\t\t\tsynchronized (lock) {\n\t\t\t\t\tSystem.out.println(\"线程2执行。\");\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tThread.sleep(10000);\n\t\t\t\t} catch (InterruptedException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tnew Thread(r1).start();\n\t\tnew Thread(r2).start();\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470290", + "status": 1, + "keywords": "算法高阶,多线程算法,算法问题选编,动态多线程基础", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/36.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/37.json b/data_backup/java_code_json/37.json new file mode 100644 index 000000000..732fadaf0 --- /dev/null +++ b/data_backup/java_code_json/37.json @@ -0,0 +1,17 @@ +{ + "question_id": 202236, + "question_title": "字符串交错组成", + "question_content": "对于三个字符串A,B,C。我们称C由A和B交错组成当且仅当C包含且仅包含A,B中所有字符,且对应的顺序不改变。请编写一个高效算法,判断C串是否由A和B交错组成。\n给定三个字符串A,B和C,及他们的长度。请返回一个bool值,代表C是否由A和B交错组成。保证三个串的长度均小于等于100。\n测试样例:\n\"ABC\",3,\"12C\",3,\"A12BCC\",6\n返回:true", + "difficulty": "简单", + "answer_id": 126531, + "answer_content": "\n\n```\n import java.util.*;\n \npublic class Mixture {\n public boolean chkMixture(String A, int n, String B, int m, String C, int v) {\n // write code here\n return chkMixture(A,B,C,A.length()-1,B.length()-1,C.length()-1);\n }\n public static boolean chkMixture(String A,String B, String C,int i,int j,int k){\n if(k == 0){\n return true;\n }\n if(i == 0){\n if(B.charAt(j) == C.charAt(k)){\n return chkMixture(A,B,C,0,j-1,k-1);\n }else{\n return false;\n }\n }\n if(j == 0){\n if(A.charAt(i) == C.charAt(k)){\n return chkMixture(A,B,C,i-1,0,k-1);\n }else{\n return false;\n }\n }\n boolean res1 = false;\n boolean res2 = false;\n if(A.charAt(i) == C.charAt(k)){\n res1 = chkMixture(A,B,C,i-1,j,k-1);\n }\n if(B.charAt(j) == C.charAt(k)){\n res2 = chkMixture(A,B,C,i,j-1,k-1);\n }\n return res1||res2;\n }\n}\n```\n\n", + "tag_name": "java", + "java": "public class Mixture {\n\tpublic boolean chkMixture(String A, int n, String B, int m, String C, int v) {\n\t\treturn chkMixture(A,B,C,A.length()-1,B.length()-1,C.length()-1);\n\t}\n\tpublic static boolean chkMixture(String A,String B, String C,int i,int j,int k){\n\t\tif(k == 0){\n\t\t\treturn true;\n\t\t}\n\t\tif(i == 0){\n\t\t\tif(B.charAt(j) == C.charAt(k)){\n\t\t\t\treturn chkMixture(A,B,C,0,j-1,k-1);\n\t\t\t}else{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\tif(j == 0){\n\t\t\tif(A.charAt(i) == C.charAt(k)){\n\t\t\t\treturn chkMixture(A,B,C,i-1,0,k-1);\n\t\t\t}else{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\tboolean res1 = false;\n\t\tboolean res2 = false;\n\t\tif(A.charAt(i) == C.charAt(k)){\n\t\t\tres1 = chkMixture(A,B,C,i-1,j,k-1);\n\t\t}\n\t\tif(B.charAt(j) == C.charAt(k)){\n\t\t\tres2 = chkMixture(A,B,C,i,j-1,k-1);\n\t\t}\n\t\treturn res1||res2;\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469979", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,朴素字符串匹配算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/37.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/38.json b/data_backup/java_code_json/38.json new file mode 100644 index 000000000..8dee67692 --- /dev/null +++ b/data_backup/java_code_json/38.json @@ -0,0 +1,17 @@ +{ + "question_id": 507751, + "question_title": "怎么样能在一个字符串里判断是否包含数组里的内容?", + "question_content": "例如:\n\nstring a=\"ILOVEU\";\nstring[] F={\"I\",\"L\",\"U\"};\n循环条件?\n if(怎么判断a是否在数组F里)\n {\n 在F里并且提取出来\n }ELSE{不在}\n", + "difficulty": "简单", + "answer_id": 438340, + "answer_content": "\n\n```\n // 判断字符串在数组内\n\tpublic static void stringInArray() {\n\t\tString str = \"HELL\";\n\t\tString[] arr = { \"H\", \"E\", \"L\", \"L\", \"O\" };\n\t\tboolean flag = true;\n\t\tfor (int i = 0; i < str.length() && flag; i++) {\n\t\t\tString item = String.valueOf(str.charAt(i));\n\t\t\tfor (String aa : arr) {\n\t\t\t\tif (aa.equals(item)) {\n\t\t\t\t\tSystem.out.println(item + \"在数组内\");\n\t\t\t\t\tflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t}\n\t\tif (flag) {\n\t\t\tSystem.out.println(\"字符串在数组内。\");\n\t\t} else {\n\t\t\tSystem.out.println(\"字符串不在数组内。\");\n\t\t}\n\t}\n\n\t// 判断数组在字符串内\n\tpublic static void arrayInString() {\n\t\tString str = \"HELLO\";\n\t\tString[] arr = { \"H\", \"E\", \"L\", \"L\", \"O\" };\n\t\tboolean flag = true;\n\t\tfor (String aa : arr) {\n\t\t\tif (!str.contains(aa)) {\n\t\t\t\tSystem.out.println(\"字符串不包含:\" + aa);\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (flag) {\n\t\t\tSystem.out.println(\"数组在字符串内。\");\n\t\t} else {\n\t\t\tSystem.out.println(\"数组不在字符串内。\");\n\t\t}\n\t}\n```\n感觉这是最笨的方法了。\n", + "tag_name": "java", + "java": "\tpublic static void stringInArray() {\n\t\tString str = \"HELL\";\n\t\tString[] arr = { \"H\", \"E\", \"L\", \"L\", \"O\" };\n\t\tboolean flag = true;\n\t\tfor (int i = 0; i < str.length() && flag; i++) {\n\t\t\tString item = String.valueOf(str.charAt(i));\n\t\t\tfor (String aa : arr) {\n\t\t\t\tif (aa.equals(item)) {\n\t\t\t\t\tSystem.out.println(item + \"在数组内\");\n\t\t\t\t\tflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t}\n\t\tif (flag) {\n\t\t\tSystem.out.println(\"字符串在数组内。\");\n\t\t} else {\n\t\t\tSystem.out.println(\"字符串不在数组内。\");\n\t\t}\n\t}\n\tpublic static void arrayInString() {\n\t\tString str = \"HELLO\";\n\t\tString[] arr = { \"H\", \"E\", \"L\", \"L\", \"O\" };\n\t\tboolean flag = true;\n\t\tfor (String aa : arr) {\n\t\t\tif (!str.contains(aa)) {\n\t\t\t\tSystem.out.println(\"字符串不包含:\" + aa);\n\t\t\t\tflag = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (flag) {\n\t\t\tSystem.out.println(\"数组在字符串内。\");\n\t\t} else {\n\t\t\tSystem.out.println(\"数组不在字符串内。\");\n\t\t}\n\t}", + "topic_link": "https://bbs.csdn.net/topics/600470194", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/38.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/39.json b/data_backup/java_code_json/39.json new file mode 100644 index 000000000..238787032 --- /dev/null +++ b/data_backup/java_code_json/39.json @@ -0,0 +1,18 @@ +{ + "question_id": 375089, + "question_title": "替换任何位置的字符串", + "question_content": "字符串形如 \"00??00\", \"0?00?0\", \"0??00?\", 6位定长,'?' 数量和位置都不确定。\n如何将所有的 '?' 都替换成0~9 并输出?\n例如\n输入:\"0?00?0\", \n输出:\"000000\", \"000010\"...\"000090\", \"010000\"...\"010090\"...\"090090\", \n即 第一个为0,第二个从0增加到9;然后第一个为1,第二个从0增加到9....; 第一个为9,第二个从0增加到9。 ", + "difficulty": "中等", + "answer_id": 404427, + "answer_content": "\n**楼主自己看看吧,只实现了部分累加,工作原因,不能全部实现了,逻辑上没有问题了,剩下的交给你了,原创!**\n```\n import java.util.ArrayList;\nimport java.util.List;\n\npublic class Demo1 {\n\n\tpublic static void main(String[] args) {\n\n\t\tStringBuffer str = new StringBuffer(\"?0?0?0\");\n\n\t\tList numList = new ArrayList();\n\n\t\twhile (true) {\n\n\t\t\tint num = str.indexOf(\"?\");\n\t\t\tif (num == -1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tnumList.add(num);\n\t\t\tstr = str.replace(num, num + 1, \"0\");\n\t\t}\n\t\tint j = 0;\n\t\tfor (int i = numList.size() - 1; i >= 0; i--) {\n\t\t\tfor (; j <= 9; j++) {\n\t\t\t\tstr = str.replace(numList.get(i), numList.get(i) + 1, \"\" + j);\n\t\t\t\tSystem.out.println(str);\n\t\t\t\tif (j == 9) {\n\t\t\t\t\tstr = str.replace(numList.get(i), numList.get(i) + 1, \"\" + 0);\n\t\t\t\t\tj=1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n}\n```\n\n", + "tag_name": "java", + "java": "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Demo1 {\n\tpublic static void main(String[] args) {\n\t\tStringBuffer str = new StringBuffer(\"0??00?\");\n\t\tList numList = new ArrayList();\n\t\twhile (true) {\n\t\t\tint num = str.indexOf(\"?\");\n\t\t\tif (num == -1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tnumList.add(num);\n\t\t\tstr = str.replace(num, num + 1, \"0\");\n\t\t}\n\t\tint j = 0;\n\t\tfor (int i = numList.size() - 1; i >= 0; i--) {\n\t\t\tfor (; j <= 9; j++) {\n\t\t\t\tstr = str.replace(numList.get(i), numList.get(i) + 1, \"\" + j);\n\t\t\t\tSystem.out.println(str);\n\t\t\t\tif (j == 9) {\n\t\t\t\t\tstr = str.replace(numList.get(i), numList.get(i) + 1, \"\" + 0);\n\t\t\t\t\tj = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470195", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/39.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/4.json b/data_backup/java_code_json/4.json new file mode 100644 index 000000000..0c9d35234 --- /dev/null +++ b/data_backup/java_code_json/4.json @@ -0,0 +1,18 @@ +{ + "question_id": 7463161, + "question_title": "求输入数字的平均值、最大值", + "question_content": "

输入若干个数,设输入的第一个数n为后面要输入的数的个数,求平均值及最大值,并在屏幕输出来

", + "difficulty": "简单", + "answer_id": 53448940, + "answer_content": "

在测试类中,从键盘输入一些数就好了

\n\n
\nimport java.util.Scanner;\n    public class Test{\n        public static void main(String[] args) {\n            Scanner in=new Scanner(System.in);\n            System.out.println("输入n:");\n            int n=in.nextInt();\n            int temp,max=0,sum=0;\n            for(int i=0;i<n;i++){\n                temp=in.nextInt();\n                if (temp>max){\n                    max=temp;\n                }\n                sum+=temp;\n            }\n            System.out.println("最大值为:"+max+",平均值为:"+sum*1.0/n);\n        }\n    }\n
\n\n

\"\"

\n", + "tag_name": "java", + "java": "import java.util.Scanner;\npublic class Test{\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tSystem.out.println(\"输入n:\");\n\t\tint n=in.nextInt();\n\t\tint temp,max=0,sum=0;\n\t\tfor(int i=0;imax){\n\t\t\t\tmax=temp;\n\t\t\t}\n\t\t\tsum+=temp;\n\t\t}\n\t\tSystem.out.println(\"最大值为:\"+max+\",平均值为:\"+sum*1.0/n);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469973", + "status": 1, + "keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/4.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/40.json b/data_backup/java_code_json/40.json new file mode 100644 index 000000000..fa58e898f --- /dev/null +++ b/data_backup/java_code_json/40.json @@ -0,0 +1,18 @@ +{ + "question_id": 1442463, + "question_title": "字符串排序", + "question_content": "
  1. 将一组乱序的字符进行排序,使其变成有序(假设有8个字符并都不相同),然后任意输入一个字符,按字母顺序找到其合适的位置插入到字符序列中。
\n

System.out.println("请输入要插入的字符:");

\n

      char num=input.next().charAt(0);
\n如:原始字符序列位O T Y A E V B Z,首先排序输出A B E O T V Y Z,然后输入K,找到K所在的位置并插入,最终结果为 A B E K O T V Y Z

", + "difficulty": "中等", + "answer_id": 5034877, + "answer_content": "
\n public static void test(String s, char c) {      //冒泡排序\n\n        char[] arr = s.toCharArray();        //字符串->字符串数组\n        for (int i = 0; i < arr.length; i++) {\n            for (int j = i + 1; j < arr.length; j++) {\n                if (arr[i] > arr[j]) {\n                    char temp = arr[i];\n                    arr[i] = arr[j];\n                    arr[j] = temp;\n                }\n            }\n\n        }\n        String b = new String(arr);\n        System.out.println("对字符串排序后:" + b);\n        StringBuilder sb = new StringBuilder(b);\n        if (c <= b.charAt(0)) {\n            sb.insert(0, c);\n        }\n        else if (c >= b.charAt(b.length() - 1)) {\n            sb.insert(b.length(), c);\n        }else {\n            for (int i = 0; i < b.length() - 1; i++) {\n                if (c > b.charAt(i) && c < b.charAt(i + 1)) {\n                    sb.insert(i + 1, c);\n                    break;\n                }\n            }\n        }\n        System.out.println(String.format("插入字符串%c后:%s", c, sb));\n    }\n\n    public static void main(String[] args) {\n        test("gdjfgkjryitybdsgsfdgpiop", 'z');\n        test("gdjfgkjryitytommybdsgsfdgpiop", 'a');\n        test("uyrgfsdyzwsgkjk", 'h');\n    }
\n\n

希望对你有帮助

", + "tag_name": "java", + "java": "class java_1442463 {\n\tpublic static void test(String s, char c) {\n\t\tchar[] arr = s.toCharArray();\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tfor (int j = i + 1; j < arr.length; j++) {\n\t\t\t\tif (arr[i] > arr[j]) {\n\t\t\t\t\tchar temp = arr[i];\n\t\t\t\t\tarr[i] = arr[j];\n\t\t\t\t\tarr[j] = temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tString b = new String(arr);\n\t\tSystem.out.println(\"对字符串排序后:\" + b);\n\t\tStringBuilder sb = new StringBuilder(b);\n\t\tif (c <= b.charAt(0)) {\n\t\t\tsb.insert(0, c);\n\t\t} else if (c >= b.charAt(b.length() - 1)) {\n\t\t\tsb.insert(b.length(), c);\n\t\t} else {\n\t\t\tfor (int i = 0; i < b.length() - 1; i++) {\n\t\t\t\tif (c > b.charAt(i) && c < b.charAt(i + 1)) {\n\t\t\t\t\tsb.insert(i + 1, c);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(String.format(\"插入字符串%c后:%s\", c, sb));\n\t}\n\tpublic static void main(String[] args) {\n\t\ttest(\"gdjfgkjryitybdsgsfdgpiop\", 'z');\n\t\ttest(\"gdjfgkjryitytommybdsgsfdgpiop\", 'a');\n\t\ttest(\"uyrgfsdyzwsgkjk\", 'h');\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470291", + "status": 0, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/40.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/41.json b/data_backup/java_code_json/41.json new file mode 100644 index 000000000..94dbacdf6 --- /dev/null +++ b/data_backup/java_code_json/41.json @@ -0,0 +1,17 @@ +{ + "question_id": 186251, + "question_title": "把ArrayList集合写入txt文件", + "question_content": "如何把ArrayList集合写入txt文件", + "difficulty": "简单", + "answer_id": 79188, + "answer_content": "\n\n```\n import java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.util.ArrayList;\n \npublic class ArrayToTxt {\n public static void main(String[] args) throws Exception{\n File f=new File(\"d:/1.txt\");\n ArrayList al=new ArrayList();\n al.add(\"first\");\n al.add(\"second\");\n al.add(\"third\");\n BufferedWriter bw=new BufferedWriter(new FileWriter(f));\n for(int i=0;i al=new ArrayList();\n\t\tal.add(\"first\");\n\t\tal.add(\"second\");\n\t\tal.add(\"third\");\n\t\tBufferedWriter bw=new BufferedWriter(new FileWriter(f));\n\t\tfor(int i=0;i,key为每一个字符,value为字符出现的字数;\n\t3、遍历当前的数组,将数组中每一个不重复的字符作为HashMap对象中的key,判断当前的HashMap对象中是否存在当前的key\n\t\t\t1)若存在,取出对应的value,将value值加1后,再保存到对应的key上;\n\t\t\t2)若不存在,则将当前的key值对应的value赋值为1;\n\t4、遍历统计结束的HashMap对象,取出所有key中value最大的对象即可;\n\n代码如下:\n\npublic static void main(String[] args) {\n\t\tString string = \"Thinking in Java\";\n\t\tchar[] ch = string.toCharArray();\n\t\tMap result = new HashMap();\n\t\tfor (int i = 0; i < ch.length; i++) {\n\t\t\tif (result.containsKey(ch[i])) {\n\t\t\t\tint count = result.get(ch[i]) + 1;\n\t\t\t\tresult.put(ch[i], count);\n\t\t\t} else {\n\t\t\t\tresult.put(ch[i], 1);\n\t\t\t}\n\t\t}\n\t\tCharacter maxChar = null;\n\t\tInteger maxCount = 0;\n\t\tfor (Entry entry : result.entrySet()) {\n\t\t\tif (entry.getValue() > maxCount) {\n\t\t\t\tmaxChar = entry.getKey();\n\t\t\t\tmaxCount = entry.getValue();\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(\"字符: \" + maxChar + \" 出现的字数最多,为 \" + maxCount + \" 次\");\n\t}\n\n希望对你有帮助!", + "tag_name": "java", + "java": "import java.util.HashMap;\nimport java.util.Map;\nclass java_256052 {\n public static void main(String[] args) {\n\t String string = \"Thinking in Java\";\n\t char[] ch = string.toCharArray();\n\t Map result = new HashMap();\n\t for (int i = 0; i < ch.length; i++) {\n\t\t if (result.containsKey(ch[i])) {\n\t\t\tint count = result.get(ch[i]) + 1;\n\t\t\tresult.put(ch[i], count);\n\t\t } else {\n\t\t\tresult.put(ch[i], 1);\n\t\t }\n\t }\n\t Character maxChar = null;\n\t Integer maxCount = 0;\n\t for (java.util.Map.Entry entry : result.entrySet()) {\n\t\t if (entry.getValue() > maxCount) {\n\t\t\tmaxChar = entry.getKey();\n\t\t\tmaxCount = entry.getValue();\n\t\t }\n\t }\n\t System.out.println(\"字符: \" + maxChar + \" 出现的字数最多,为 \" + maxCount + \" 次\");\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600469881", + "status": 1, + "keywords": "算法高阶,计算几何学,算法问题选编,确定任意一对线段是否相交", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/42.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/43.json b/data_backup/java_code_json/43.json new file mode 100644 index 000000000..4a9249aad --- /dev/null +++ b/data_backup/java_code_json/43.json @@ -0,0 +1,18 @@ +{ + "question_id": 7415408, + "question_title": "猜数字游戏", + "question_content": "

1、猜数字游戏
\n一个类A有一个实例变量v,从键盘接收一个正整数作为实例变量v的初始值。
\n另外再定义一个类B,对A类的实例变量v进行猜测。
\n    如果大了则提示大了
\n    小了则提示小了
\n    等于则提示猜测成功

", + "difficulty": "简单", + "answer_id": 53368860, + "answer_content": "
\nimport java.util.Random;\nimport java.util.Scanner;\n\n\npublic class Demo {\n\n    public static void main(String[] args) {\n        // 开始游戏\n        System.out.println("猜数字游戏开始");\n        System.out.println("输入1-100之间的数据:");\n\n        // 创建Random类变量(获取随机数)\n        Random ran = new Random();\n        // 创建 0-100 随机数(初始值)\n        int v = ran.nextInt(100)+1;\n\n        // 创建Scanner类变量(用户输入猜测值)\n        Scanner in = new Scanner(System.in);\n\n        // 循环猜测\n        while(true) {\n            // 得到用户输入猜测值\n            int b = in.nextInt();\n            // 比较用户输入猜测值和随机数(初始值)\n            if(b > v) {\n                System.out.println("您猜测得数字较大,请继续猜测!");\n            }else if(b < v) {\n                System.out.println("您猜测得数字较小,请继续猜测!");\n            } else {\n                System.out.println("恭喜你,猜对了!");\n                System.out.println("游戏结束!");\n                \n                // 用户输入猜测值和随机数(初始值) 相等时,结束程序\n                break;\n            }\n        }\n    }\n}\n
\n\n

 

", + "tag_name": "java", + "java": "import java.util.Random;\nimport java.util.Scanner;\npublic class Demo {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"猜数字游戏开始\");\n\t\tSystem.out.println(\"输入1-100之间的数据:\");\n\t\tRandom ran = new Random();\n\t\tint v = ran.nextInt(100) + 1;\n\t\tScanner in = new Scanner(System.in);\n\t\twhile (true) {\n\t\t\tint b = in.nextInt();\n\t\t\tif (b > v) {\n\t\t\t\tSystem.out.println(\"您猜测得数字较大,请继续猜测!\");\n\t\t\t} else if (b < v) {\n\t\t\t\tSystem.out.println(\"您猜测得数字较小,请继续猜测!\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"恭喜你,猜对了!\");\n\t\t\t\tSystem.out.println(\"游戏结束!\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470292", + "status": 0, + "keywords": "B树,算法高阶,B树的定义,高级数据结构", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/43.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/44.json b/data_backup/java_code_json/44.json new file mode 100644 index 000000000..a04663601 --- /dev/null +++ b/data_backup/java_code_json/44.json @@ -0,0 +1,18 @@ +{ + "question_id": 339311, + "question_title": "找质数", + "question_content": "找出大于200的最小的质数", + "difficulty": "简单", + "answer_id": 337929, + "answer_content": "\n\n```\n /* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\nclass Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tint n = 201;\n\t\twhile (true)\n\t\t{\n\t\t\tboolean b = true;\n\t\t\tfor (int i = 2; i < n / 2; i++)\n\t\t\t{\n\t\t\t\tif (n % i == 0) b = false;\n\t\t\t}\n\t\t\tif (b) break;\n\t\t\tn++;\n\t\t}\n\t\tSystem.out.println(n);\n\t}\n}\n```\n\n\n\n\n在线验证\nhttp://ideone.com/pVj7iy\n\n211", + "tag_name": "java", + "java": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nclass Ideone {\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tint n = 201;\n\t\twhile (true) {\n\t\t\tboolean b = true;\n\t\t\tfor (int i = 2; i < n / 2; i++) {\n\t\t\t\tif (n % i == 0)\n\t\t\t\t\tb = false;\n\t\t\t}\n\t\t\tif (b)\n\t\t\t\tbreak;\n\t\t\tn++;\n\t\t}\n\t\tSystem.out.println(n);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469980", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/44.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/45.json b/data_backup/java_code_json/45.json new file mode 100644 index 000000000..275eced91 --- /dev/null +++ b/data_backup/java_code_json/45.json @@ -0,0 +1,18 @@ +{ + "question_id": 7457133, + "question_title": "设计学生类Student和它的一个子类Undergraduate", + "question_content": "

设计一个学生类Student和它的一个子类Undergraduate,要求如下:\n(1)Student类有name和age属性,一个包含两个人参数的构造器,用于给两属性赋值,一个show()方法打印Student的属性信息。\n(2)本科生类Undergraduate增加一个degree(学位)属性。有一个包含三参数的构造器,前两个参数用于给集成的属性赋值,第三个参数给degree专业见值,一个show()方法用于打印Undergraduate的属性信息。\n(3)在测试类中分别打印Undergraduate和Student对象,调用它们的show()\n 

", + "difficulty": "简单", + "answer_id": 53441266, + "answer_content": "
\npackage T1;\n\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\t// 有参构造\n\t\tStudent stu = new Student("student", 100);\n\t\tstu.show();\n\t\tUndergraduate undergraduate = new Undergraduate("Undergraduate", 20, "本科");\n\t\tundergraduate.show();\n\t}\n\n}\n\nclass Student {\n\n\t// 姓名\n\tprivate String name;\n\n\t// 成绩\n\tprivate int age;\n\n\t// 无参构造\n\tpublic Student() {\n\t\tsuper();\n\t}\n\n\t// 全参构造\n\tpublic Student(String name, int age) {\n\t\tthis.name = name;\n\t\tthis.age = age;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic double getAge() {\n\t\treturn age;\n\t}\n\n\tpublic void setAge(int age) {\n\t\tthis.age = age;\n\t}\n\n\tpublic void show() {\n\t\tSystem.out.println("名字:" + this.name + "\\t年龄:" + this.age);\n\t}\n\n}\n\nclass Undergraduate extends Student {\n\tprivate String degree;\n\n\tpublic Undergraduate(String name, int age, String degree) {\n\t\tsuper(name, age);\n\t\tthis.degree = degree;\n\t}\n\n\tpublic void show() {\n\t\tSystem.out.println("名字:" + super.getName() + "\\t年龄:" + super.getAge() + "\\t学位:" + this.degree);\n\t}\n\n}\n
\n\n

 

\n", + "tag_name": "java", + "java": "package T1;\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tStudent stu = new Student(\"student\", 100);\n\t\tstu.show();\n\t\tUndergraduate undergraduate = new Undergraduate(\"Undergraduate\", 20, \"本科\");\n\t\tundergraduate.show();\n\t}\n}\nclass Student {\n\tprivate String name;\n\tprivate int age;\n\tpublic Student() {\n\t\tsuper();\n\t}\n\tpublic Student(String name, int age) {\n\t\tthis.name = name;\n\t\tthis.age = age;\n\t}\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\tpublic double getAge() {\n\t\treturn age;\n\t}\n\tpublic void setAge(int age) {\n\t\tthis.age = age;\n\t}\n\tpublic void show() {\n\t\tSystem.out.println(\"名字:\" + this.name + \"\\t年龄:\" + this.age);\n\t}\n}\nclass Undergraduate extends Student {\n\tprivate String degree;\n\tpublic Undergraduate(String name, int age, String degree) {\n\t\tsuper(name, age);\n\t\tthis.degree = degree;\n\t}\n\tpublic void show() {\n\t\tSystem.out.println(\"名字:\" + super.getName() + \"\\t年龄:\" + super.getAge() + \"\\t学位:\" + this.degree);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470293", + "status": 1, + "keywords": "算法初阶,基础知识,算法基础,设计算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/45.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/46.json b/data_backup/java_code_json/46.json new file mode 100644 index 000000000..8e65f60b5 --- /dev/null +++ b/data_backup/java_code_json/46.json @@ -0,0 +1,18 @@ +{ + "question_id": 187492, + "question_title": "求素数和", + "question_content": "求第m个到第n个素数之间的素数和", + "difficulty": "中等", + "answer_id": 82090, + "answer_content": "加个变量控制一下就行了。\n\n```\npublic class All {\n\tpublic static void main(String[] args) {\n\t\tint a[] = new int[200];\n\t\tint index = 0;\n\t\t// 将前200个数中的素数提取出来放入数组a中\n\t\tfor (int i = 1; i < 200; i++) {\n\t\t\tboolean isPrime = true;\n\t\t\tfor (int k = 2; k < i; k++) {\n\t\t\t\tif (i % k == 0) {\n\t\t\t\t\tisPrime = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (isPrime) {\n\t\t\t\ta[index++] = i;\n\t\t\t\tSystem.out.println(a[index-1]); // 打印确认\n\t\t\t}\n\t\t}\n\t\t// 输入两个数 m,n 求第m个素数到底n个素数之间的素数和\n\t\tScanner small = new Scanner(System.in);\n\t\tScanner large = new Scanner(System.in);\n\t\tint m = small.nextInt();\n\t\tint n = large.nextInt();\n\t\tint sums = 0;\n\t\tint suml = 0;\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tsums += a[i];\n\t\t\tSystem.out.print(a[i] + \"*\");\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsuml += a[i];\n\t\t\tSystem.out.print(a[i] + \" \");\n\t\t}\n\t\tsum = suml - sums;\n\t\tSystem.out.println(sum);\n\t}\n}\n```\n\n", + "tag_name": "java", + "java": "import java.util.Scanner;\npublic class All {\n public static void main(String[] args) {\n\t int a[] = new int[200];\n\t int index = 0;\n\t for (int i = 1; i < 200; i++) {\n\t\t boolean isPrime = true;\n\t\t for (int k = 2; k < i; k++) {\n\t\t\tif (i % k == 0) {\n\t\t\t isPrime = false;\n\t\t\t break;\n\t\t\t}\n\t\t }\n\t\t if (isPrime) {\n\t\t\ta[index++] = i;\n\t\t\tSystem.out.println(a[index - 1]);\n\t\t }\n\t }\n\t Scanner small = new Scanner(System.in);\n\t Scanner large = new Scanner(System.in);\n\t int m = small.nextInt();\n\t int n = large.nextInt();\n\t int sums = 0;\n\t int suml = 0;\n\t int sum = 0;\n\t for (int i = 0; i < m; i++) {\n\t\t sums += a[i];\n\t\t System.out.print(a[i] + \"*\");\n\t }\n\t for (int i = 0; i < n; i++) {\n\t\t suml += a[i];\n\t\t System.out.print(a[i] + \" \");\n\t }\n\t sum = suml - sums;\n\t System.out.println(sum);\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600470196", + "status": 1, + "keywords": "算法高阶,数论算法,素数的测试,算法问题选编", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/46.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/47.json b/data_backup/java_code_json/47.json new file mode 100644 index 000000000..014297b7d --- /dev/null +++ b/data_backup/java_code_json/47.json @@ -0,0 +1,17 @@ +{ + "question_id": 7396323, + "question_title": "String字符串 数字+英文字符组合,如何排序(字母按A-Z,数字按从小到大)", + "question_content": " 举例:\n \n \"A1,A2,A5,A4,A3,B2,B3,B5,B1,B4,C1,C3,C5,C2\"\n \n \n \n 排序后:\n \n \n \"A1,A2,A3,A4,A5,B1,B2,B3,B4,B5,C1,C2,C3,C5\"", + "difficulty": "中等", + "answer_id": 53339978, + "answer_content": "
\nimport org.apache.commons.lang3.StringUtils;\n\nimport java.util.Arrays;\nimport java.util.Comparator;\n\npublic class Test {\n    public static void main(String[] args) {\n        String[] str = "A1,A11,A2,A5,A4,A3,B2,B3,B5,B1,B4,C1,C3,C5,C2".split(",");//先分割出来\n        //Arrays.sort(str);//从小到大排序,按ACS码值\n        //重写比较器,定义怎么比较\n        Arrays.sort(str, new Comparator<String>()\n        {\n            @Override\n            public int compare(String o1, String o2) {\n                char s1 = o1.charAt(0);//第一个字符\n                char s2 = o2.charAt(0);\n                if(s1 == s2){\n                    Integer i1 = Integer.valueOf(o1.substring(1));//取剩下的字符串,也就是数字部分\n                    Integer i2 = Integer.valueOf(o2.substring(1));\n                    return i1.compareTo(i2);\n                }else{\n                    return o1.compareTo(o2);\n                }\n            }\n        });\n        String str2 = StringUtils.join(str, ",");//数组转字符串(逗号分隔)\n        System.out.println(str2);\n    }\n}
\n\n

测试结果:

\n\n

\"\"

", + "tag_name": "java", + "java": "import org.apache.commons.lang3.StringUtils;\nimport java.util.Arrays;\nimport java.util.Comparator;\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tString[] str = \"A1,A11,A2,A5,A4,A3,B2,B3,B5,B1,B4,C1,C3,C5,C2\".split(\",\");\n\t\tArrays.sort(str, new Comparator()\n\t\t{\n\t\t\t@Override\n\t\t\tpublic int compare(String o1, String o2) {\n\t\t\t\tchar s1 = o1.charAt(0);\n\t\t\t\tchar s2 = o2.charAt(0);\n\t\t\t\tif(s1 == s2){\n\t\t\t\t\tInteger i1 = Integer.valueOf(o1.substring(1));\n\t\t\t\t\tInteger i2 = Integer.valueOf(o2.substring(1));\n\t\t\t\t\treturn i1.compareTo(i2);\n\t\t\t\t}else{\n\t\t\t\t\treturn o1.compareTo(o2);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tString str2 = StringUtils.join(str, \",\");\n\t\tSystem.out.println(str2);\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470197", + "status": 0, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/47.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/48.json b/data_backup/java_code_json/48.json new file mode 100644 index 000000000..0dea72658 --- /dev/null +++ b/data_backup/java_code_json/48.json @@ -0,0 +1,17 @@ +{ + "question_id": 379228, + "question_title": "实现一元二次方程ax*x+b*x+c=0", + "question_content": "用面向对象的思想实现一元二次方程ax*x+b*x+c=0\n a,b,c从键盘输入\n", + "difficulty": "简单", + "answer_id": 411678, + "answer_content": "代码如下,希望对你有用\n\n```\n package question;\n//创建Function类,用以实现功能\npublic class Function {\n\t//私有化成员变量a,b,c\n\tprivate double a;\n\tprivate double b;\n\tprivate double c;\n\t//为每个成员变量提供set/get方法\n\tpublic double getA() {\n\t\treturn a;\n\t}\n\tpublic void setA(double a) {\n\t\tthis.a = a;\n\t}\n\tpublic double getB() {\n\t\treturn b;\n\t}\n\tpublic void setB(double b) {\n\t\tthis.b = b;\n\t}\n\tpublic double getC() {\n\t\treturn c;\n\t}\n\tpublic void setC(double c) {\n\t\tthis.c = c;\n\t}\n\t//提供无参、有参构造方法\n\tpublic Function() {}\n\tpublic Function(double a, double b, double c) {\n\t\tthis.a = a;\n\t\tthis.b = b;\n\t\tthis.c = c;\n\t}\n\t//提供成员方法,用以解决二次函数问题\n\tpublic void quadratic(){\n\t\tdouble d=b*b-4*a*c;\n\t\tif (Math.pow(d, 0.5)>=0) {\n\t\t\t//求根公式\n\t\t\tdouble q1=(-b)+Math.pow(d, 0.5);\n\t\t\tdouble q2=(-b)-Math.pow(d, 0.5);\n\t\t\tSystem.out.println(q1+\" \"+q2);\t\n\t\t}else {\n\t\t\tSystem.out.println(\"没有实根\");\n\t\t}\n\t}\n}\n\n```\n然后,\n\n```\n package question;\n//创建Test类,用以测试程序\nimport java.util.Scanner;//导包\n\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);//创建键盘录入对象\n\t\tSystem.out.println(\"请输入a的值\");//接收键盘录入数据\n\t\tdouble a=sc.nextDouble();\n\t\tSystem.out.println(\"请输入b的值\");//接收键盘录入数据\n\t\tdouble b=sc.nextDouble();\n\t\tSystem.out.println(\"请输入c的值\");//接收键盘录入数据\n\t\tdouble c=sc.nextDouble();\n\t\tFunction f = new Function(a,b,c);//调用方法Function\n\t\tf.quadratic();\n\t}\n\n}\n\n```\n\n\n", + "tag_name": "java", + "java": "public class Function {\n private double a;\n private double b;\n private double c;\n public double getA() {\n return a;\n }\n public void setA(double a) {\n this.a = a;\n }\n public double getB() {\n return b;\n }\n public void setB(double b) {\n this.b = b;\n }\n public double getC() {\n return c;\n }\n public void setC(double c) {\n this.c = c;\n }\n public Function() {}\n public Function(double a, double b, double c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n public void quadratic(){\n double d=b*b-4*a*c;\n if (Math.pow(d, 0.5)>=0) {\n double q1=(-b)+Math.pow(d, 0.5);\n double q2=(-b)-Math.pow(d, 0.5);\n System.out.println(q1+\" \"+q2); \n }else {\n System.out.println(\"没有实根\");\n }\n }\n}", + "topic_link": "https://bbs.csdn.net/topics/600469882", + "status": 0, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/48.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/49.json b/data_backup/java_code_json/49.json new file mode 100644 index 000000000..55260cb8a --- /dev/null +++ b/data_backup/java_code_json/49.json @@ -0,0 +1,18 @@ +{ + "question_id": 658117, + "question_title": "获取硬盘信息", + "question_content": "获取硬盘的分区信息,以及每个分区的磁盘空间及剩余空间", + "difficulty": "简单", + "answer_id": 471171, + "answer_content": "\n\n```\n import java.io.File;\nimport java.text.DecimalFormat;\n\npublic class Ypxx {\n public static void main(String[] args) {\n File[] roots = File.listRoots();// 获取磁盘分区列表\n for (File file : roots) {\n System.out.println(file.getPath() + \"信息如下:\");\n long free = file.getFreeSpace();\n long total = file.getTotalSpace();\n long use = total - free;\n System.out.println(\"空闲未使用 = \" + change(free) + \"G\");// 空闲空间\n System.out.println(\"已经使用 = \" + change(use) + \"G\");// 可用空间\n System.out.println(\"总容量 = \" + change(total) + \"G\");// 总空间\n System.out.println(\"使用百分比 = \" + bfb(use, total));\n System.out.println();\n }\n }\n\n public static long change(long num) {\n // return num;\n return num / 1024 / 1024 / 1024;\n }\n\n public static String bfb(Object num1, Object num2) {\n double val1 = Double.valueOf(num1.toString());\n double val2 = Double.valueOf(num2.toString());\n if (val2 == 0) {\n return \"0.0%\";\n } else {\n DecimalFormat df = new DecimalFormat(\"#0.00\");\n return df.format(val1 / val2 * 100) + \"%\";\n }\n }\n}\n\n```\n\n", + "tag_name": "java", + "java": "import java.io.File;\nimport java.text.DecimalFormat;\npublic class Ypxx {\n\tpublic static void main(String[] args) {\n\t\tFile[] roots = File.listRoots();\n\t\tfor (File file : roots) {\n\t\t\tSystem.out.println(file.getPath() + \"信息如下:\");\n\t\t\tlong free = file.getFreeSpace();\n\t\t\tlong total = file.getTotalSpace();\n\t\t\tlong use = total - free;\n\t\t\tSystem.out.println(\"空闲未使用 = \" + change(free) + \"G\");\n\t\t\tSystem.out.println(\"已经使用 = \" + change(use) + \"G\");\n\t\t\tSystem.out.println(\"总容量 = \" + change(total) + \"G\");\n\t\t\tSystem.out.println(\"使用百分比 = \" + bfb(use, total));\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\tpublic static long change(long num) {\n\t\treturn num / 1024 / 1024 / 1024;\n\t}\n\tpublic static String bfb(Object num1, Object num2) {\n\t\tdouble val1 = Double.valueOf(num1.toString());\n\t\tdouble val2 = Double.valueOf(num2.toString());\n\t\tif (val2 == 0) {\n\t\t\treturn \"0.0%\";\n\t\t} else {\n\t\t\tDecimalFormat df = new DecimalFormat(\"#0.00\");\n\t\t\treturn df.format(val1 / val2 * 100) + \"%\";\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470294", + "status": 1, + "keywords": "计算机", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/49.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/5.json b/data_backup/java_code_json/5.json new file mode 100644 index 000000000..82f7ccd1e --- /dev/null +++ b/data_backup/java_code_json/5.json @@ -0,0 +1,18 @@ +{ + "question_id": 194042, + "question_title": "java String字符串截取", + "question_content": "比如这样一个字符串\nString a = \"你好,今天是@2015@年@7@月@15@日\";\nString b = \"时间为@16@@:@@05@\";\n怎么样截取2个一对的@中间的字符串 a = 2015,7,15 b = 16,:,05", + "difficulty": "简单", + "answer_id": 100456, + "answer_content": "\n\n```\n public static String getResult(String str,String splitStr){\n \tString[] arr = (\"1\"+str+\"1\").split(splitStr);\n \tStringBuilder sd = new StringBuilder();\n \tfor(int i=1;i 2的16次方需要用long接收返回值\n * @return\n */\n public int multiplication(){\n return n1*n2;\n }\n\n private int division(){\n if (n2 == 0){\n throw new IllegalArgumentException(\"除数参数不合法\");\n }\n return n1/n2;\n }\n\n /**\n * 如果要返回小数,用这种\n */\n/* private double division(){\n if (n2 == 0){\n throw new IllegalArgumentException(\"除数参数不合法\");\n }\n return n1/(n2*1.0);\n }\n */\n public static void main(String[] args) {\n Number number = new Number(6,0);\n System.out.println(number.addition());\n System.out.println(number.subtration());\n System.out.println(number.multiplication());\n try {\n System.out.println(number.division());\n }catch (Exception e){\n System.out.println(e.getMessage());\n }\n }\n}\n```", + "tag_name": "java", + "java": "public class Number {\n\tprivate int n1;\n\tprivate int n2;\n\tpublic Number(int n1, int n2) {\n\t\tthis.n1 = n1;\n\t\tthis.n2 = n2;\n\t}\n\tpublic int addition() {\n\t\treturn n1 + n2;\n\t}\n\tpublic int subtration() {\n\t\treturn n1 - n2;\n\t}\n\tpublic int multiplication() {\n\t\treturn n1 * n2;\n\t}\n\tprivate int division() {\n\t\tif (n2 == 0) {\n\t\t\tthrow new IllegalArgumentException(\"除数参数不合法\");\n\t\t}\n\t\treturn n1 / n2;\n\t}\n\tpublic static void main(String[] args) {\n\t\tNumber number = new Number(6, 0);\n\t\tSystem.out.println(number.addition());\n\t\tSystem.out.println(number.subtration());\n\t\tSystem.out.println(number.multiplication());\n\t\ttry {\n\t\t\tSystem.out.println(number.division());\n\t\t} catch (Exception e) {\n\t\t\tSystem.out.println(e.getMessage());\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469981", + "status": 1, + "keywords": "算法初阶,基础知识,分治策略,用主方法求解递归式", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/50.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/6.json b/data_backup/java_code_json/6.json new file mode 100644 index 000000000..da983b782 --- /dev/null +++ b/data_backup/java_code_json/6.json @@ -0,0 +1,17 @@ +{ + "question_id": 201530, + "question_title": "输出给定字符串在哪些文件中出现过,把文件名称输出,包括路径", + "question_content": "输入:\n1) 给定一个文件夹,此文件夹下面有若干个文件或者文件夹,文件夹下面也有文件。文件全部为文本文件,文件中的内容不确定。如C:\\TxtFiles\n2) 给定一个字符串,如test\n\n要求输出给定字符串在哪些文件中出现过,把文件名称输出,包括路径。", + "difficulty": "简单", + "answer_id": 124339, + "answer_content": "\n\n```\n import java.util.*;\nimport java.io.*;\n\npublic class ReadStringAndPrintPath \n{\n\tpublic static void main(String[] args) \n\t{\n\t\tSystem.out.println(\"Hello World!\");\n\t\tString str = \"test\";\n\t\tFile file = new File(\"a\");\n\t\tFile[] list = file.listFiles();\n\t\tsearchString(list,str);\n\t}\n\tpublic static void searchString(File[] files,String str){\n\t\tfor(int i = 0 ; i < files.length; i ++){\n\t\t\tif(files[i].isFile()){\n\t\t\t\t//是文件,搜索是否存在字符串\n\t\t\t\ttry{\n\t\t\t\t\tScanner scan = new Scanner(files[i]);\n\t\t\t\t\twhile(scan.hasNext()){\n\t\t\t\t\t\tif(scan.nextLine().indexOf(str) != -1){\n\t\t\t\t\t\t\tSystem.out.println(files[i].getAbsolutePath());\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}catch(IOException ex){\n\t\t\t\t\tex.printStackTrace();\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\t//是文件夹\n\t\t\t\tFile[] list = files[i].listFiles();\n\t\t\t\tsearchString(list,str);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n", + "tag_name": "java", + "java": " import java.util.*;\nimport java.io.*;\npublic class ReadStringAndPrintPath \n{\n\tpublic static void main(String[] args) \n\t{\n\t\tSystem.out.println(\"Hello World!\");\n\t\tString str = \"test\";\n\t\tFile file = new File(\"a\");\n\t\tFile[] list = file.listFiles();\n\t\tsearchString(list,str);\n\t}\n\tpublic static void searchString(File[] files,String str){\n\t\tfor(int i = 0 ; i < files.length; i ++){\n\t\t\tif(files[i].isFile()){\n\t\t\t\ttry{\n\t\t\t\t\tScanner scan = new Scanner(files[i]);\n\t\t\t\t\twhile(scan.hasNext()){\n\t\t\t\t\t\tif(scan.nextLine().indexOf(str) != -1){\n\t\t\t\t\t\t\tSystem.out.println(files[i].getAbsolutePath());\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}catch(IOException ex){\n\t\t\t\t\tex.printStackTrace();\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tFile[] list = files[i].listFiles();\n\t\t\t\tsearchString(list,str);\n\t\t\t}\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469871", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,Rabin\\Karp算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/6.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/java_code_json/7.json b/data_backup/java_code_json/7.json new file mode 100644 index 000000000..0fe5490ae --- /dev/null +++ b/data_backup/java_code_json/7.json @@ -0,0 +1,18 @@ +{ + "question_id": 7458996, + "question_title": "输出每天是应该学习还是休息还是锻炼", + "question_content": "

30天中,从第一天开始五天学习,一天休息、一天锻炼,输出每天是应该学习还是休息还是锻炼

", + "difficulty": "简单", + "answer_id": 53443776, + "answer_content": "
\npublic class HelloWorld {\n    public static void main(String []args) {\n\t\tint n1=0,n2=0,n3=0,i;\n       for(i=1;i<=30;i++){\n\t   if(n1<5){\n\t\tSystem.out.println("学习");\n\t\t   n1++;\n\t\t   continue;\n\t   }\n\t\telse{\n\t\tSystem.out.println("休息");\n\t\tSystem.out.println("锻炼");\n\t\t\tn1=0;\n\t\t\ti++;\n\t\t}\n    }\n\t}}
\n\n

\"\" 

\n", + "tag_name": "java", + "java": "public class HelloWorld {\n\tpublic static void main(String []args) {\n\t\tint n1=0,n2=0,n3=0,i;\n\t\tfor(i=1;i<=30;i++){\n\t\t\tif(n1<5){\n\t\t\t\tSystem.out.println(\"学习\");\n\t\t\t\tn1++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"休息\");\n\t\t\t\tSystem.out.println(\"锻炼\");\n\t\t\t\tn1=0;\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600470187", + "status": 1, + "keywords": "数学", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/7.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/8.json b/data_backup/java_code_json/8.json new file mode 100644 index 000000000..1eac0044c --- /dev/null +++ b/data_backup/java_code_json/8.json @@ -0,0 +1,18 @@ +{ + "question_id": 371986, + "question_title": "用随机数相关知识解答随机分组问题", + "question_content": "已知有16只男子足球队参加2008年奥运会。写一段程序将球队随机分成4组", + "difficulty": "简单", + "answer_id": 398940, + "answer_content": "刚写的代码附上,亲测可行,希望有帮助。\n\n\n\n```\n import java.util.*;\n\nclass StringToDateDemo {\n\n\tpublic static void main(String args[]) {\n\t\t//假设a-p为16个队名称\n\t\tArrayList teams = new ArrayList() {\n\t\t\t{\n\t\t\t\tadd(\"a\");\n\t\t\t\tadd(\"b\");\n\t\t\t\tadd(\"c\");\n\t\t\t\tadd(\"d\");\n\t\t\t\tadd(\"e\");\n\t\t\t\tadd(\"f\");\n\t\t\t\tadd(\"g\");\n\t\t\t\tadd(\"h\");\n\t\t\t\tadd(\"i\");\n\t\t\t\tadd(\"j\");\n\t\t\t\tadd(\"k\");\n\t\t\t\tadd(\"l\");\n\t\t\t\tadd(\"m\");\n\t\t\t\tadd(\"n\");\n\t\t\t\tadd(\"o\");\n\t\t\t\tadd(\"p\");\n\t\t\t}\n\t\t};\n\n\t\tCollections.shuffle(teams);// **这行是关键,shuffle函数将16个队随机打乱**\n\n\t\t// 将16个队分成4组\n\t\tArrayList group1 = new ArrayList();\n\t\tArrayList group2 = new ArrayList();\n\t\tArrayList group3 = new ArrayList();\n\t\tArrayList group4 = new ArrayList();\n\n\t\t// 添加第一组成员\n\t\tgroup1.addAll(teams.subList(0, teams.size() / 4 + teams.size() % 4));\n\n\t\t// 添加第二组成员\n\t\tgroup2.addAll(teams.subList(teams.size() / 4 + teams.size() % 4, 2 * teams.size() / 4 + teams.size() % 4));\n\n\t\t// 添加第三组成员\n\t\tgroup3.addAll(teams.subList(2*teams.size() / 4 + teams.size() % 4, 3 * teams.size() / 4 + teams.size() % 4));\n\n\t\t// 添加第四组成员\n\t\tgroup4.addAll(teams.subList(3*teams.size() / 4 + teams.size() % 4, teams.size()));\n\t}\n}\n```\n\n", + "tag_name": "java", + "java": "import java.util.*;\nclass StringToDateDemo {\n\tpublic static void main(String args[]) {\n\t\tArrayList teams = new ArrayList() {\n\t\t\t{\n\t\t\t\tadd(\"a\");\n\t\t\t\tadd(\"b\");\n\t\t\t\tadd(\"c\");\n\t\t\t\tadd(\"d\");\n\t\t\t\tadd(\"e\");\n\t\t\t\tadd(\"f\");\n\t\t\t\tadd(\"g\");\n\t\t\t\tadd(\"h\");\n\t\t\t\tadd(\"i\");\n\t\t\t\tadd(\"j\");\n\t\t\t\tadd(\"k\");\n\t\t\t\tadd(\"l\");\n\t\t\t\tadd(\"m\");\n\t\t\t\tadd(\"n\");\n\t\t\t\tadd(\"o\");\n\t\t\t\tadd(\"p\");\n\t\t\t}\n\t\t};\n\t\tCollections.shuffle(teams);\n\t\tArrayList group1 = new ArrayList();\n\t\tArrayList group2 = new ArrayList();\n\t\tArrayList group3 = new ArrayList();\n\t\tArrayList group4 = new ArrayList();\n\t\tgroup1.addAll(teams.subList(0, teams.size() / 4 + teams.size() % 4));\n\t\tgroup2.addAll(teams.subList(teams.size() / 4 + teams.size() % 4, 2 * teams.size() / 4 + teams.size() % 4));\n\t\tgroup3.addAll(teams.subList(2*teams.size() / 4 + teams.size() % 4, 3 * teams.size() / 4 + teams.size() % 4));\n\t\tgroup4.addAll(teams.subList(3*teams.size() / 4 + teams.size() % 4, teams.size()));\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469872", + "status": 1, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/8.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/java_code_json/9.json b/data_backup/java_code_json/9.json new file mode 100644 index 000000000..044ce5310 --- /dev/null +++ b/data_backup/java_code_json/9.json @@ -0,0 +1,18 @@ +{ + "question_id": 7410647, + "question_title": "定义一个学生类,其中有学号、姓名、年龄3个数据成员,以及若干成员函数。", + "question_content": "

同时编写主函数使用这个类,实现对学生数据的赋值和输出。要求:使用构造函数实现对数据的初始化,使用成员函数实现对数据的输出。

", + "difficulty": "简单", + "answer_id": 53361432, + "answer_content": "

完整代码如下:

\n\n
\npackage com.test;\n\n/**\n * @author 杨俊\n * @create 2021-03-27-11:14\n */\npublic class Student {\n    public String stuNo;\n    public String stuname;\n    public int age;\n\n    public Student(String stuNo,String stuname,int age){\n        this.stuNo=stuNo;\n        this.stuname=stuname;\n        this.age=age;\n    }\n\n    public static void printStudent(Student stu){\n        System.out.println("学号:"+stu.getStuNo());\n        System.out.println("姓名:"+stu.getStuname());\n        System.out.println("年龄:"+stu.getAge());\n    }\n\n    public static void main(String[] args) {\n        Student stu = new Student("101","杨俊",28);\n        printStudent(stu);\n    }\n\n    public String getStuNo() {\n        return stuNo;\n    }\n\n    public void setStuNo(String stuNo) {\n        this.stuNo = stuNo;\n    }\n\n    public String getStuname() {\n        return stuname;\n    }\n\n    public void setStuname(String stuname) {\n        this.stuname = stuname;\n    }\n\n    public int getAge() {\n        return age;\n    }\n\n    public void setAge(int age) {\n        this.age = age;\n    }\n}
\n\n

 

\n\n

运行截图

\n\n

\"\"

", + "tag_name": "java", + "java": "public class Student {\n\tpublic String stuNo;\n\tpublic String stuname;\n\tpublic int age;\n\tpublic Student(String stuNo,String stuname,int age){\n\t\tthis.stuNo=stuNo;\n\t\tthis.stuname=stuname;\n\t\tthis.age=age;\n\t}\n\tpublic static void printStudent(Student stu){\n\t\tSystem.out.println(\"学号:\"+stu.getStuNo());\n\t\tSystem.out.println(\"姓名:\"+stu.getStuname());\n\t\tSystem.out.println(\"年龄:\"+stu.getAge());\n\t}\n\tpublic static void main(String[] args) {\n\t\tStudent stu = new Student(\"101\",\"杨俊\",28);\n\t\tprintStudent(stu);\n\t}\n\tpublic String getStuNo() {\n\t\treturn stuNo;\n\t}\n\tpublic void setStuNo(String stuNo) {\n\t\tthis.stuNo = stuNo;\n\t}\n\tpublic String getStuname() {\n\t\treturn stuname;\n\t}\n\tpublic void setStuname(String stuname) {\n\t\tthis.stuname = stuname;\n\t}\n\tpublic int getAge() {\n\t\treturn age;\n\t}\n\tpublic void setAge(int age) {\n\t\tthis.age = age;\n\t}\n}", + "topic_link": "https://bbs.csdn.net/topics/600469873", + "status": 0, + "keywords": "算法初阶,基础知识,分治策略,证明主定理,对b的幂证明主定理", + "license": "csdn.net", + "notebook": { + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/9.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/0.json b/data_backup/leetcode/0.json new file mode 100644 index 000000000..1cb189603 --- /dev/null +++ b/data_backup/leetcode/0.json @@ -0,0 +1,24 @@ +{ + "question_id": 1, + "question_title": "两数之和", + "difficulty": "简单", + "question_content": "

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。

你可以按任意顺序返回答案。

 

示例 1:

输入:nums = [2,7,11,15], target = 9
输出:
[0,1]
解释:
因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。

示例 2:

输入:nums = [3,2,4], target = 6
输出:
[1,2]

示例 3:

输入:nums = [3,3], target = 6
输出:
[0,1]

 

提示:

    \t
  • 2 <= nums.length <= 103
  • \t
  • -109 <= nums[i] <= 109
  • \t
  • -109 <= target <= 109
  • \t
  • 只会存在一个有效答案
", + "topic_link": "https://bbs.csdn.net/topics/600470217", + "cpp": "#include \nclass Solution\n{\npublic:\n\tvector twoSum(vector &nums, int target)\n\t{\n\t\tstd::unordered_map hset;\n\t\tvector r;\n\t\tfor (int i = 0; i < nums.size(); ++i)\n\t\t{\n\t\t\tint c = target - nums[i];\n\t\t\tauto iter = hset.find(c);\n\t\t\tif (iter != hset.end() && iter->second != i)\n\t\t\t{\n\t\t\t\tr.push_back(i);\n\t\t\t\tr.push_back(iter->second);\n\t\t\t\treturn r;\n\t\t\t}\n\t\t\thset.insert(std::make_pair(nums[i], i));\n\t\t}\n\t\treturn r;\n\t}\n};", + "java": "class Solution {\n\tpublic int[] twoSum(int[] nums, int target) {\n\t\tMap cache = new HashMap<>();\n\t\tfor (int i = 0; i < nums.length; i++) {\n\t\t\tint distance = target - nums[i];\n\t\t\tif (cache.containsKey(distance)) {\n\t\t\t\treturn new int[] { cache.get(distance), i };\n\t\t\t} else {\n\t\t\t\tcache.put(nums[i], i);\n\t\t\t}\n\t\t}\n\t\treturn new int[] {};\n\t}\n}", + "js": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[]}\n */\nvar twoSum = function(nums, target) {\n const cache={};\n for(let i=0;i给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。

请你将两个数相加,并以相同形式返回一个表示和的链表。

你可以假设除了数字 0 之外,这两个数都不会以 0 开头。

 

示例 1:

\"\"
输入:l1 = [2,4,3], l2 = [5,6,4]
输出:
[7,0,8]
解释:
342 + 465 = 807.

示例 2:

输入:l1 = [0], l2 = [0]
输出:
[0]

示例 3:

输入:l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
输出:
[8,9,9,9,0,0,0,1]

 

提示:

    \t
  • 每个链表中的节点数在范围 [1, 100]
  • \t
  • 0 <= Node.val <= 9
  • \t
  • 题目数据保证列表表示的数字不含前导零
", + "topic_link": "https://bbs.csdn.net/topics/600469916", + "cpp": "struct ListNode\n{\n\tint val;\n\tstruct ListNode *next;\n};\nstruct ListNode *addTwoNumbers(struct ListNode *l1, struct ListNode *l2)\n{\n\tstruct ListNode *pp = NULL, *p = l1;\n\tstruct ListNode *qp = NULL, *q = l2;\n\tint carry = 0;\n\twhile (p != NULL && q != NULL)\n\t{\n\t\tp->val += q->val + carry;\n\t\tcarry = 0;\n\t\tif (p->val >= 10)\n\t\t{\n\t\t\tcarry = 1;\n\t\t\tp->val -= 10;\n\t\t}\n\t\tpp = p;\n\t\tp = p->next;\n\t\tqp = q;\n\t\tq = q->next;\n\t}\n\tif (q)\n\t{\n\t\tpp->next = p = q;\n\t\tqp->next = NULL;\n\t}\n\twhile (carry && p)\n\t{\n\t\tp->val += carry;\n\t\tcarry = 0;\n\t\tif (p->val >= 10)\n\t\t{\n\t\t\tcarry = 1;\n\t\t\tp->val -= 10;\n\t\t}\n\t\tpp = p;\n\t\tp = p->next;\n\t}\n\tif (carry)\n\t{\n\t\tstruct ListNode *n = (struct ListNode *)malloc(sizeof(struct ListNode));\n\t\tn->val = 1;\n\t\tn->next = NULL;\n\t\tpp->next = n;\n\t}\n\treturn l1;\n}", + "java": "class ListNode {\n\tint val;\n\tListNode next;\n\tListNode() {\n\t}\n\tListNode(int val) {\n\t\tthis.val = val;\n\t}\n\tListNode(int val, ListNode next) {\n\t\tthis.val = val;\n\t\tthis.next = next;\n\t}\n}\nclass Solution {\n\tpublic ListNode addTwoNumbers(ListNode l1, ListNode l2) {\n\t\tListNode lrr = l1;\n\t\twhile (true) {\n\t\t\tl1.val = l1.val + l2.val;\n\t\t\tif (l1.next == null && l2.next == null && l1.val < 10) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (l1.next == null) {\n\t\t\t\tl1.next = new ListNode(0);\n\t\t\t}\n\t\t\tif (l2.next == null) {\n\t\t\t\tl2.next = new ListNode(0);\n\t\t\t}\n\t\t\tif (l1.val >= 10) {\n\t\t\t\tl1.val = l1.val - 10;\n\t\t\t\tl1.next.val += 1;\n\t\t\t}\n\t\t\tl1 = l1.next;\n\t\t\tl2 = l2.next;\n\t\t}\n\t\treturn lrr;\n\t}\n}", + "js": "function ListNode(val) {\n this.val = val;\n this.next = null;\n}\n\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar addTwoNumbers = function(l1, l2) {\n\n let lrr = l1;\n\n while(true){\n\n l1.val = l1.val + l2.val;\n \n if(l1.next==null&&l2.next==null&&l1.val<10){\n break;\n }\n \n if(l1.next==null){\n l1.next=new ListNode(0);\n }\n \n if(l2.next==null){\n l2.next=new ListNode(0);\n }\n \n if(l1.val>=10){\n l1.val = l1.val - 10;\n l1.next.val+=1;\n }\n \n l1 = l1.next;\n l2 = l2.next;\n }\n \n return lrr;\n};\n", + "python": "class ListNode:\n\tdef __init__(self, val=0, next=None):\n\t\tself.val = val\n\t\tself.next = next\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution:\n\tdef addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:\n\t\tlrr = l1\n\t\twhile True:\n\t\t\tl1.val = l1.val + l2.val\n\t\t\tif l1.next is None and l2.next is None and l1.val < 10:\n\t\t\t\tbreak\n\t\t\tif l1.next is None:\n\t\t\t\tl1.next = ListNode(0)\n\t\t\tif l2.next is None:\n\t\t\t\tl2.next = ListNode(0)\n\t\t\tif l1.val >= 10:\n\t\t\t\tl1.val = l1.val - 10\n\t\t\t\tl1.next.val += 1\n\t\t\tl1 = l1.next\n\t\t\tl2 = l2.next\n\t\treturn lrr\n# %%\nl = LinkList()\nlist1 = [2,4,3]\nlist2 = [5,6,4]\nl1 = l.initList(list1)\nl2 = l.initList(list2)\ns = Solution()\nprint(l.convert_list(s.addTwoNumbers(l1, l2)))", + "status": 1, + "keywords": "递归,链表,数学", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/1/1_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/1/1_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/1/1_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/10.json b/data_backup/leetcode/10.json new file mode 100644 index 000000000..40ea4ef42 --- /dev/null +++ b/data_backup/leetcode/10.json @@ -0,0 +1,24 @@ +{ + "question_id": 11, + "question_title": "盛最多水的容器", + "difficulty": "中等", + "question_content": "

给你 n 个非负整数 a1,a2,...,an每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai)(i, 0) 。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。

说明:你不能倾斜容器。

 

示例 1:

\"\"

输入:[1,8,6,2,5,4,8,3,7]
输出:
49
解释:
图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49。

示例 2:

输入:height = [1,1]
输出:
1

示例 3:

输入:height = [4,3,2,1,4]
输出:
16

示例 4:

输入:height = [1,2,1]
输出:
2

 

提示:

    \t
  • n = height.length
  • \t
  • 2 <= n <= 3 * 104
  • \t
  • 0 <= height[i] <= 3 * 104
", + "topic_link": "https://bbs.csdn.net/topics/600469816", + "cpp": "#define MAX(a, b) (((a) < (b)) ? (b) : (a))\n#define MIN(a, b) (((a) > (b)) ? (b) : (a))\nint maxArea(int *height, int heightSize)\n{\n\tint max = 0;\n\tint i = 0, j = heightSize - 1;\n\tint a;\n\twhile (i < j)\n\t{\n\t\ta = MIN(height[i], height[j]) * (j - i);\n\t\tmax = MAX(max, a);\n\t\tif (height[i] > height[j])\n\t\t\t--j;\n\t\telse\n\t\t\t++i;\n\t}\n\treturn max;\n}", + "java": "class Solution {\n\tpublic int maxArea(int[] height) {\n\t\tint N = height.length;\n\t\tint i = 0;\n\t\tint j = N - 1;\n\t\tint max = 0;\n\t\twhile (i < j) {\n\t\t\tint c = (j - i) * Math.min(height[i], height[j]);\n\t\t\tif (c > max) {\n\t\t\t\tmax = c;\n\t\t\t}\n\t\t\tif (height[i] > height[j]) {\n\t\t\t\tj--;\n\t\t\t} else {\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n}", + "js": "/**\n * @param {number[]} height\n * @return {number}\n */\nvar maxArea = function(height) {\n let N = height.length;\n \n let i=0;\n let j=N-1;\n let max=0;\n while(imax){\n max = c;\n }\n if(height[i]>height[j]){\n j--;\n }else{\n i++;\n }\n }\n return max;\n};\n", + "python": "from typing import List\nclass Solution:\n\tdef maxArea(self, height: List[int]) -> int:\n\t\tN = len(height)\n\t\ti = 0\n\t\tj = N-1\n\t\tmax_area = 0\n\t\twhile i < j:\n\t\t\tc = (j-i)*min(height[i], height[j])\n\t\t\tif c > max_area:\n\t\t\t\tmax_area = c\n\t\t\tif height[i] > height[j]:\n\t\t\t\tj -= 1\n\t\t\telse:\n\t\t\t\ti += 1\n\t\treturn max_area\n# %%\ns = Solution()\nprint(s.maxArea([1,8,6,2,5,4,8,3,7]))", + "status": 1, + "keywords": "贪心,数组,双指针", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/10/10_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/10/10_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/10/10_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/11.json b/data_backup/leetcode/11.json new file mode 100644 index 000000000..b0717a915 --- /dev/null +++ b/data_backup/leetcode/11.json @@ -0,0 +1,24 @@ +{ + "question_id": 12, + "question_title": "整数转罗马数字", + "difficulty": "中等", + "question_content": "
\n

罗马数字包含以下七种字符: I, V, X, LCD 和 M。\n

\n\n
字符          数值\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
\n\n

例如, 罗马数字 2 写做 II ,即为两个并列的 1。12\n 写做 XII ,即为 X + II 。 27\n 写做  XXVII,\n 即为 XX + V + II 。

\n\n

通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做 IIII,而是 IV。数字 1 在数字 5 的左边,所表示的数等于大数 5\n 减小数 1 得到的数值 4 。同样地,数字 9 表示为 IX。这个特殊的规则只适用于以下六种情况:

\n\n
    \n
  • I 可以放在 V (5) 和 X (10) 的左边,来表示 4 和 9。
  • \n
  • X 可以放在 L (50) 和 C (100) 的左边,来表示 40\n 和 90。 
  • \n
  • C 可以放在 D (500) 和 M (1000) 的左边,来表示 400\n 和 900。
  • \n
\n\n

给你一个整数,将其转为罗马数字。

\n\n

 

\n\n

示例 1:

\n\n
输入: num = 3\n
输出:
\"III\"
\n\n

示例 2:

\n\n
输入: num = 4\n
输出:
\"IV\"
\n\n

示例 3:

\n\n
输入: num = 9\n
输出:
\"IX\"
\n\n

示例 4:

\n\n
输入: num = 58\n
输出:
\"LVIII\"\n
解释:
L = 50, V = 5, III = 3.\n
\n\n

示例 5:

\n\n
输入: num = 1994\n
输出:
\"MCMXCIV\"\n
解释:
M = 1000, CM = 900, XC = 90, IV = 4.
\n\n

 

\n\n

提示:

\n\n
    \n
  • 1 <= num <= 3999
  • \n
\n
", + "topic_link": "https://bbs.csdn.net/topics/600469817", + "cpp": "struct rmap\n{\n\tchar *r;\n\tint v;\n} units[] = {\n\t{\"M\", 1000},\n\t{\"CM\", 900},\n\t{\"D\", 500},\n\t{\"CD\", 400},\n\t{\"C\", 100},\n\t{\"XC\", 90},\n\t{\"L\", 50},\n\t{\"XL\", 40},\n\t{\"X\", 10},\n\t{\"IX\", 9},\n\t{\"V\", 5},\n\t{\"IV\", 4},\n\t{\"I\", 1}};\n#include \nchar result[64];\nchar *intToRoman(int num)\n{\n\tresult[0] = 0;\n\tint ri = 0;\n\tint i = 0;\n\twhile (num)\n\t{\n\t\tif (num >= units[i].v)\n\t\t{\n\t\t\tstrcat(result, units[i].r);\n\t\t\tnum -= units[i].v;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ti++;\n\t\t}\n\t}\n\treturn result;\n}", + "java": "class Solution {\n\tpublic String intToRoman(int num) {\n\t\tint f = 1000;\n\t\tint f2 = 1000;\n\t\tchar[] sym = new char[] { 'M', 'D', 'C', 'L', 'X', 'V', 'I' };\n\t\tint fsi = 0;\n\t\tint[] s = new int[] { 2, 5 };\n\t\tint si = 0;\n\t\tint[] s2 = new int[] { 10, 1 };\n\t\tint si2 = 0;\n\t\tStringBuilder roman = new StringBuilder();\n\t\twhile (num > 0) {\n\t\t\tint d = (int) Math.floor(num / f);\n\t\t\tint r = num % f;\n\t\t\tint d2 = (int) Math.floor(num / f2);\n\t\t\tint r2 = num % f2;\n\t\t\tif (d > 0) {\n\t\t\t\tif (d == 4) {\n\t\t\t\t\troman.append(sym[fsi]);\n\t\t\t\t\troman.append(sym[fsi - 1]);\n\t\t\t\t\tnum = r;\n\t\t\t\t} else if (d2 == 9) {\n\t\t\t\t\troman.append(sym[fsi + 1]);\n\t\t\t\t\troman.append(sym[fsi - 1]);\n\t\t\t\t\tnum = r2;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < d; i++) {\n\t\t\t\t\t\troman.append(sym[fsi]);\n\t\t\t\t\t}\n\t\t\t\t\tnum = r;\n\t\t\t\t}\n\t\t\t}\n\t\t\tf = f / s[si];\n\t\t\tsi++;\n\t\t\tsi %= 2;\n\t\t\tf2 = f2 / s2[si2];\n\t\t\tsi2++;\n\t\t\tsi2 %= 2;\n\t\t\tfsi++;\n\t\t}\n\t\treturn roman.toString();\n\t}\n}", + "js": "/**\n * @param {number} num\n * @return {string}\n */\nvar intToRoman = function(num) {\n \n let f = 1000;\n let f2 = 1000;\n \n let sym = ['M','D','C','L','X','V','I'];\n let fsi = 0;\n \n let s = [2,5];\n let si = 0;\n \n let s2 = [10,1];\n let si2 = 0;\n \n let roman = [];\n while(num>0){\n let d = Math.floor(num/f);\n let r = num%f;\n \n let d2 = Math.floor(num/f2);\n let r2 = num%f2;\n\n if(d>0){\n if(d===4){\n roman.push(sym[fsi]);\n roman.push(sym[fsi-1]); \n num = r;\n }else if(d2===9){\n roman.push(sym[fsi+1]);\n roman.push(sym[fsi-1]);\n num = r2;\n }else{\n for(let i=0;i str:\n\t\tf = 1000\n\t\tf2 = 1000\n\t\tsym = ['M', 'D', 'C', 'L', 'X', 'V', 'I']\n\t\tfsi = 0\n\t\ts = [2, 5]\n\t\tsi = 0\n\t\ts2 = [10, 1]\n\t\tsi2 = 0\n\t\troman = []\n\t\twhile num > 0:\n\t\t\td = floor(num/f)\n\t\t\tr = num % f\n\t\t\td2 = floor(num/f2)\n\t\t\tr2 = num % f2\n\t\t\tif d > 0:\n\t\t\t\tif d == 4:\n\t\t\t\t\troman.append(sym[fsi])\n\t\t\t\t\troman.append(sym[fsi-1])\n\t\t\t\t\tnum = r\n\t\t\t\telif d2 == 9:\n\t\t\t\t\troman.append(sym[fsi+1])\n\t\t\t\t\troman.append(sym[fsi-1])\n\t\t\t\t\tnum = r2\n\t\t\t\telse:\n\t\t\t\t\ti = 0\n\t\t\t\t\twhile i < d:\n\t\t\t\t\t\troman.append(sym[fsi])\n\t\t\t\t\t\ti += 1\n\t\t\t\t\tnum = r\n\t\t\tf = f/s[si]\n\t\t\tsi += 1\n\t\t\tsi %= 2\n\t\t\tf2 = f2/s2[si2]\n\t\t\tsi2 += 1\n\t\t\tsi2 %= 2\n\t\t\tfsi += 1\n\t\treturn ''.join(roman)\n# %%\ns = Solution()\nprint(s.intToRoman(num = 3))", + "status": 1, + "keywords": "哈希表,数学,字符串", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/11/11_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/11/11_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/11/11_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/12.json b/data_backup/leetcode/12.json new file mode 100644 index 000000000..3f22e1c79 --- /dev/null +++ b/data_backup/leetcode/12.json @@ -0,0 +1,24 @@ +{ + "question_id": 13, + "question_title": "罗马数字转整数", + "difficulty": "简单", + "question_content": "
\n

罗马数字包含以下七种字符: I, V, X, LCD 和 M。\n

\n\n
字符          数值\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000
\n\n

例如, 罗马数字 2 写做 II ,即为两个并列的 1。12\n 写做 XII ,即为 X + II 。 27\n 写做  XXVII,\n 即为 XX + V + II 。

\n\n

通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做 IIII,而是 IV。数字 1 在数字 5 的左边,所表示的数等于大数 5\n 减小数 1 得到的数值 4 。同样地,数字 9 表示为 IX。这个特殊的规则只适用于以下六种情况:

\n\n
    \n
  • I 可以放在 V (5) 和 X (10) 的左边,来表示 4 和 9。
  • \n
  • X 可以放在 L (50) 和 C (100) 的左边,来表示 40\n 和 90。 
  • \n
  • C 可以放在 D (500) 和 M (1000) 的左边,来表示 400\n 和 900。
  • \n
\n\n

给你一个整数,将其转为罗马数字。

\n\n

 

\n\n

示例 1:

\n\n
输入: num = 3\n
输出:
\"III\"
\n\n

示例 2:

\n\n
输入: num = 4\n
输出:
\"IV\"
\n\n

示例 3:

\n\n
输入: num = 9\n
输出:
\"IX\"
\n\n

示例 4:

\n\n
输入: num = 58\n
输出:
\"LVIII\"\n
解释:
L = 50, V = 5, III = 3.\n
\n\n

示例 5:

\n\n
输入: num = 1994\n
输出:
\"MCMXCIV\"\n
解释:
M = 1000, CM = 900, XC = 90, IV = 4.
\n\n

 

\n\n

提示:

\n\n
    \n
  • 1 <= num <= 3999
  • \n
\n
", + "topic_link": "https://bbs.csdn.net/topics/600470218", + "cpp": "struct rmap\n{\n\tchar *r;\n\tint v;\n\tint l;\n} units[] = {\n\t{\"M\", 1000, 1},\n\t{\"CM\", 900, 2},\n\t{\"D\", 500, 1},\n\t{\"CD\", 400, 2},\n\t{\"C\", 100, 1},\n\t{\"XC\", 90, 2},\n\t{\"L\", 50, 1},\n\t{\"XL\", 40, 2},\n\t{\"X\", 10, 1},\n\t{\"IX\", 9, 2},\n\t{\"V\", 5, 1},\n\t{\"IV\", 4, 2},\n\t{\"I\", 1, 1}};\n#include \nint romanToInt(char *s)\n{\n\tint len = strlen(s);\n\tchar *end = s + len;\n\tint i = 0;\n\tint r = 0;\n\twhile (i < 13)\n\t{\n\t\tif (end - s >= units[i].l && memcmp(s, units[i].r, units[i].l) == 0)\n\t\t{\n\t\t\tr += units[i].v;\n\t\t\ts += units[i].l;\n\t\t}\n\t\telse\n\t\t\ti++;\n\t}\n\treturn r;\n}", + "java": "class Solution {\n\tpublic int romanToInt(String s) {\n\t\tint n = 0;\n\t\tfor (int i = 0; i < s.length();) {\n\t\t\tchar c = s.charAt(i);\n\t\t\tif (c == 'I') {\n\t\t\t\tif (i + 1 < s.length()) {\n\t\t\t\t\tif (s.charAt(i + 1) == 'V') {\n\t\t\t\t\t\tn += 4;\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else if (s.charAt(i + 1) == 'X') {\n\t\t\t\t\t\tn += 9;\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tn += 1;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tn += 1;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t} else if (c == 'X') {\n\t\t\t\tif (i + 1 < s.length()) {\n\t\t\t\t\tif (s.charAt(i + 1) == 'L') {\n\t\t\t\t\t\tn += 40;\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else if (s.charAt(i + 1) == 'C') {\n\t\t\t\t\t\tn += 90;\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tn += 10;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tn += 10;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t} else if (c == 'C') {\n\t\t\t\tif (i + 1 < s.length()) {\n\t\t\t\t\tif (s.charAt(i + 1) == 'D') {\n\t\t\t\t\t\tn += 400;\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else if (s.charAt(i + 1) == 'M') {\n\t\t\t\t\t\tn += 900;\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tn += 100;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tn += 100;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t} else if (c == 'V') {\n\t\t\t\tn += 5;\n\t\t\t\ti++;\n\t\t\t} else if (c == 'L') {\n\t\t\t\tn += 50;\n\t\t\t\ti++;\n\t\t\t} else if (c == 'D') {\n\t\t\t\tn += 500;\n\t\t\t\ti++;\n\t\t\t} else if (c == 'M') {\n\t\t\t\tn += 1000;\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn n;\n\t}\n}", + "js": "/**\n * @param {string} s\n * @return {number}\n */\nvar romanToInt = function(s) {\n let n = 0;\n for(let i=0;i int:\n\t\tunits = [\n\t\t\t[\"M\", 1000, 1],\n\t\t\t[\"CM\", 900, 2],\n\t\t\t[\"D\", 500, 1],\n\t\t\t[\"CD\", 400, 2],\n\t\t\t[\"C\", 100, 1],\n\t\t\t[\"XC\", 90, 2],\n\t\t\t[\"L\", 50, 1],\n\t\t\t[\"XL\", 40, 2],\n\t\t\t[\"X\", 10, 1],\n\t\t\t[\"IX\", 9, 2],\n\t\t\t[\"V\", 5, 1],\n\t\t\t[\"IV\", 4, 2],\n\t\t\t[\"I\", 1, 1]\n\t\t]\n\t\tend = len(s)\n\t\tstart = 0\n\t\ti = 0\n\t\tr = 0\n\t\twhile i < len(units):\n\t\t\tunit = units[i][0]\n\t\t\tvalue = units[i][1]\n\t\t\tstep = units[i][2]\n\t\t\tif end-start >= step and s[start:start+step] == unit:\n\t\t\t\tr += value\n\t\t\t\tstart += step\n\t\t\telse:\n\t\t\t\ti += 1\n\t\treturn r\n# %%\ns = Solution()\nprint(s.romanToInt(\"III\"))", + "status": 1, + "keywords": "哈希表,数学,字符串", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/12/12_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/12/12_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/12/12_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/13.json b/data_backup/leetcode/13.json new file mode 100644 index 000000000..a5440eedf --- /dev/null +++ b/data_backup/leetcode/13.json @@ -0,0 +1,24 @@ +{ + "question_id": 14, + "question_title": "最长公共前缀", + "difficulty": "简单", + "question_content": "

编写一个函数来查找字符串数组中的最长公共前缀。

如果不存在公共前缀,返回空字符串 \"\"

 

示例 1:

输入:strs = [\"flower\",\"flow\",\"flight\"]
输出:
\"fl\"

示例 2:

输入:strs = [\"dog\",\"racecar\",\"car\"]
输出:
\"\"
解释:
输入不存在公共前缀。

 

提示:

    \t
  • 0 <= strs.length <= 200
  • \t
  • 0 <= strs[i].length <= 200
  • \t
  • strs[i] 仅由小写英文字母组成
", + "topic_link": "https://bbs.csdn.net/topics/600469918", + "cpp": "class Solution\n{\npublic:\n\tstring longestCommonPrefix(vector &strs)\n\t{\n\t\tstring lcp;\n\t\tif (strs.size() == 0)\n\t\t\treturn lcp;\n\t\tint min_len = INT_MAX;\n\t\tint min_idx = 0;\n\t\tfor (int i = 0; i < strs.size(); ++i)\n\t\t{\n\t\t\tauto &s = strs[i];\n\t\t\tif (s.size() < min_len)\n\t\t\t{\n\t\t\t\tmin_len = s.size();\n\t\t\t\tmin_idx = i;\n\t\t\t}\n\t\t}\n\t\tauto &smin = strs[min_idx];\n\t\tfor (int i = 0; i < min_len; ++i)\n\t\t{\n\t\t\tchar c = smin[i];\n\t\t\tint j;\n\t\t\tfor (j = 0; j < strs.size(); ++j)\n\t\t\t{\n\t\t\t\tauto &cs = strs[j];\n\t\t\t\tif (c != cs[i])\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (j == strs.size())\n\t\t\t\tlcp += c;\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\t\treturn lcp;\n\t}\n};", + "java": "class Solution {\n\tpublic String longestCommonPrefix(String[] strs) {\n\t\tif (strs.length == 0) {\n\t\t\treturn \"\";\n\t\t}\n\t\tint i = 0;\n\t\tStringBuilder lcp = new StringBuilder();\n\t\twhile (true) {\n\t\t\tboolean done = false;\n\t\t\tif (i >= strs[0].length()) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int j = 0; j < strs.length; j++) {\n\t\t\t\tif (i < strs[j].length()) {\n\t\t\t\t\tif (strs[j].charAt(i) != strs[0].charAt(i)) {\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tdone = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (done) {\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tlcp.append(strs[0].charAt(i));\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn lcp.toString();\n\t}\n}", + "js": "/**\n * @param {string[]} strs\n * @return {string}\n */\nvar longestCommonPrefix = function(strs) {\n if(strs.length===0){\n return '';\n }\n \n let i=0; \n let lcp=[];\n while(true){\n let done=false;\n \n if(i>=strs[0].length){\n break;\n }\n \n for(let j=0;j str:\n\t\tif len(strs) == 0:\n\t\t\treturn ''\n\t\ti = 0\n\t\tlcp = []\n\t\twhile True:\n\t\t\tdone = False\n\t\t\tif i >= len(strs[0]):\n\t\t\t\tbreak\n\t\t\tj = 0\n\t\t\twhile j < len(strs):\n\t\t\t\tif i < len(strs[j]):\n\t\t\t\t\tif strs[j][i] != strs[0][i]:\n\t\t\t\t\t\tdone = True\n\t\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tdone = True\n\t\t\t\t\tbreak\n\t\t\t\tj += 1\n\t\t\tif not done:\n\t\t\t\tlcp.append(strs[0][i])\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\treturn ''.join(lcp)\n# %%\ns = Solution()\nprint(s.longestCommonPrefix(strs = [\"flower\",\"flow\",\"flight\"]))", + "status": 1, + "keywords": "字符串", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/13/13_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/13/13_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/13/13_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/14.json b/data_backup/leetcode/14.json new file mode 100644 index 000000000..2a5e35cf4 --- /dev/null +++ b/data_backup/leetcode/14.json @@ -0,0 +1,24 @@ +{ + "question_id": 15, + "question_title": "三数之和", + "difficulty": "中等", + "question_content": "

给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。

注意:答案中不可以包含重复的三元组。

 

示例 1:

输入:nums = [-1,0,1,2,-1,-4]
输出:
[[-1,-1,2],[-1,0,1]]

示例 2:

输入:nums = []
输出:
[]

示例 3:

输入:nums = [0]
输出:
[]

 

提示:

    \t
  • 0 <= nums.length <= 3000
  • \t
  • -105 <= nums[i] <= 105
", + "topic_link": "https://bbs.csdn.net/topics/600470113", + "cpp": "#include \n#include \nclass Solution\n{\npublic:\n\tvector> threeSum(vector &nums)\n\t{\n\t\tvector> r;\n\t\tif (nums.size() == 0)\n\t\t\treturn r;\n\t\tsort(nums.begin(), nums.end());\n\t\tint cur, left, right;\n\t\tcur = 0;\n\t\twhile (cur < nums.size())\n\t\t{\n\t\t\tif (nums[cur] > 0)\n\t\t\t\tbreak;\n\t\t\tleft = cur + 1;\n\t\t\tright = nums.size() - 1;\n\t\t\twhile (left < right)\n\t\t\t{\n\t\t\t\tint n = nums[cur] + nums[left] + nums[right];\n\t\t\t\tif (n == 0)\n\t\t\t\t{\n\t\t\t\t\tr.emplace_back(vector({nums[cur], nums[left], nums[right]}));\n\t\t\t\t\tint t = left + 1;\n\t\t\t\t\twhile (t < right && nums[t] == nums[left])\n\t\t\t\t\t\tt++;\n\t\t\t\t\tleft = t;\n\t\t\t\t\tt = right - 1;\n\t\t\t\t\twhile (t > left && nums[t] == nums[right])\n\t\t\t\t\t\tt--;\n\t\t\t\t\tright = t;\n\t\t\t\t}\n\t\t\t\telse if (n > 0)\n\t\t\t\t{\n\t\t\t\t\tint t = right - 1;\n\t\t\t\t\twhile (t > left && nums[t] == nums[right])\n\t\t\t\t\t\tt--;\n\t\t\t\t\tright = t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint t = left + 1;\n\t\t\t\t\twhile (t < right && nums[t] == nums[left])\n\t\t\t\t\t\tt++;\n\t\t\t\t\tleft = t;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint t = cur + 1;\n\t\t\twhile (t < nums.size() && nums[t] == nums[cur])\n\t\t\t\tt++;\n\t\t\tcur = t;\n\t\t}\n\t\treturn r;\n\t}\n};", + "java": "class Solution {\n\tpublic List> threeSum(int[] nums) {\n\t\tArrays.sort(nums);\n\t\tList> result = new ArrayList<>();\n\t\tint cur, left, right;\n\t\tcur = 0;\n\t\twhile (cur < nums.length) {\n\t\t\tif (nums[cur] > 0)\n\t\t\t\tbreak;\n\t\t\tleft = cur + 1;\n\t\t\tright = nums.length - 1;\n\t\t\twhile (left < right) {\n\t\t\t\tint n = nums[cur] + nums[left] + nums[right];\n\t\t\t\tif (n == 0) {\n\t\t\t\t\tList r = new ArrayList();\n\t\t\t\t\tr.add(nums[cur]);\n\t\t\t\t\tr.add(nums[left]);\n\t\t\t\t\tr.add(nums[right]);\n\t\t\t\t\tresult.add(r);\n\t\t\t\t\tint t = left + 1;\n\t\t\t\t\twhile (t < right && nums[t] == nums[left])\n\t\t\t\t\t\tt++;\n\t\t\t\t\tleft = t;\n\t\t\t\t\tt = right - 1;\n\t\t\t\t\twhile (t > left && nums[t] == nums[right])\n\t\t\t\t\t\tt--;\n\t\t\t\t\tright = t;\n\t\t\t\t} else if (n > 0) {\n\t\t\t\t\tint t = right - 1;\n\t\t\t\t\twhile (t > left && nums[t] == nums[right])\n\t\t\t\t\t\tt--;\n\t\t\t\t\tright = t;\n\t\t\t\t} else {\n\t\t\t\t\tint t = left + 1;\n\t\t\t\t\twhile (t < right && nums[t] == nums[left])\n\t\t\t\t\t\tt++;\n\t\t\t\t\tleft = t;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint t = cur + 1;\n\t\t\twhile (t < nums.length && nums[t] == nums[cur])\n\t\t\t\tt++;\n\t\t\tcur = t;\n\t\t}\n\t\treturn result;\n\t}\n}", + "js": "\n\n\nconst fs = require('fs');\nconst path = require('path');\n\n/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nvar threeSum = function(nums) {\n \n var result = [], \n unique = {},\n i,j,k,right,left,inv={}, last, list, hash;\n\n nums.sort((a,b)=>a-b);\n\n for(i=0;i=0){\n left = i;\n }\n if(right==null&&nums[i]>0){\n right = i;\n }\n inv[nums[i]] = i;\n }\n\n if(left===0){\n right = nums.length;\n }\n\n for(i=0;i= nums[j] * 2); j++){\n last = 0-nums[i]-nums[j];\n\n // do no use index of\n k = inv[last];\n if(k>j){\n list = [nums[i],nums[j],last];\n hash = `${list[0]}_${list[1]}_${list[2]}`;\n\n // do not use index of\n if(!unique[hash]){\n unique[hash] = true;\n result.push(list);\n }\n }\n }\n }\n\n return result;\n};\n\nlet testcases = [\n JSON.parse(fs.readFileSync(path.join(__dirname,'input.txt'))),\n // [-13,5,13,12,-2,-11,-1,12,-3,0,-3,-7,-7,-5,-3,-15,-2,14,14,13,6,-11,-11,5,-15,-14,5,-5,-2,0,3,-8,-10,-7,11,-5,-10,-5,-7,-6,2,5,3,2,7,7,3,-10,-2,2,-12,-11,-1,14,10,-9,-15,-8,-7,-9,7,3,-2,5,11,-13,-15,8,-3,-7,-12,7,5,-2,-6,-3,-10,4,2,-5,14,-3,-1,-10,-3,-14,-4,-3,-7,-4,3,8,14,9,-2,10,11,-10,-4,-15,-9,-1,-1,3,4,1,8,1],\n // [-2,0,0,2,2], // [[ -2, 0, 2 ]]\n // [0,0,0], // [[0,0,0]]\n // [3,0,-2,-1,1,2], // [[-2,-1,3],[-2,0,2],[-1,0,1]]\n];\n\n\nfor(const c of testcases){\n let v = threeSum(c);\n // console.log(v);\n console.log(v.length);\n}\n\n\n\n\n\n\n\n", + "python": "from typing import List\nclass Solution:\n\tdef threeSum(self, nums: List[int]) -> List[List[int]]:\n\t\tif len(nums) == 0:\n\t\t\treturn []\n\t\tresult = []\n\t\tunique = {}\n\t\tinv = {}\n\t\tleft = None\n\t\tright = None\n\t\tnums.sort()\n\t\ti = 0\n\t\twhile i < len(nums):\n\t\t\tif left == None and nums[i] >= 0:\n\t\t\t\tleft = i\n\t\t\tif right == None and nums[i] > 0:\n\t\t\t\tright = i\n\t\t\tinv[nums[i]] = i\n\t\t\ti += 1\n\t\tif left == 0:\n\t\t\tright = len(nums)\n\t\tif right is None:\n\t\t\treturn []\n\t\ti = 0\n\t\twhile i < right:\n\t\t\tj = i+1\n\t\t\twhile j < len(nums) and (-nums[i] >= nums[j] * 2):\n\t\t\t\tlast = 0-nums[i]-nums[j]\n\t\t\t\tk = inv.get(last)\n\t\t\t\tif k and k > j:\n\t\t\t\t\tlist = [nums[i], nums[j], last]\n\t\t\t\t\thash = f'{list[0]}_{list[1]}_{list[2]}'\n\t\t\t\t\tif unique.get(hash) is None:\n\t\t\t\t\t\tunique[hash] = True\n\t\t\t\t\t\tresult.append(list)\n\t\t\t\tj += 1\n\t\t\ti += 1\n\t\treturn result\n# %%\ns = Solution()\nprint(s.threeSum(nums = [-1,0,1,2,-1,-4]))", + "status": 1, + "keywords": "数组,双指针,排序", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/14/14_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/14/14_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/14/14_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/15.json b/data_backup/leetcode/15.json new file mode 100644 index 000000000..127417fd6 --- /dev/null +++ b/data_backup/leetcode/15.json @@ -0,0 +1,24 @@ +{ + "question_id": 16, + "question_title": "最接近的三数之和", + "difficulty": "中等", + "question_content": "

给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。

 

示例:

输入:nums = [-1,2,1,-4], target = 1
输出:
2
解释:
与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。

 

提示:

    \t
  • 3 <= nums.length <= 10^3
  • \t
  • -10^3 <= nums[i] <= 10^3
  • \t
  • -10^4 <= target <= 10^4
", + "topic_link": "https://bbs.csdn.net/topics/600471102", + "cpp": "#include \nclass Solution\n{\npublic:\n\tint threeSumClosest(vector &nums, int target)\n\t{\n\t\tsort(nums.begin(), nums.end());\n\t\tint cur, left, right;\n\t\tcur = 0;\n\t\tint closest = nums[0] + nums[1] + nums[2];\n\t\twhile (cur < nums.size() - 2)\n\t\t{\n\t\t\tleft = cur + 1;\n\t\t\tright = nums.size() - 1;\n\t\t\tint n;\n\t\t\twhile (left < right)\n\t\t\t{\n\t\t\t\tn = nums[cur] + nums[left] + nums[right];\n\t\t\t\tif (abs(target - n) < abs(target - closest))\n\t\t\t\t{\n\t\t\t\t\tclosest = n;\n\t\t\t\t}\n\t\t\t\tif (n == target)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if (n > target)\n\t\t\t\t{\n\t\t\t\t\tint t = right - 1;\n\t\t\t\t\twhile (t > left && nums[t] == nums[right])\n\t\t\t\t\t\tt--;\n\t\t\t\t\tright = t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint t = left + 1;\n\t\t\t\t\twhile (t < right && nums[t] == nums[left])\n\t\t\t\t\t\tt++;\n\t\t\t\t\tleft = t;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint t = cur + 1;\n\t\t\twhile (t < nums.size() && nums[t] == nums[cur])\n\t\t\t\tt++;\n\t\t\tcur = t;\n\t\t}\n\t\treturn closest;\n\t}\n};", + "java": "class Solution {\n\tint oneSumCloset(int[] nums, int i, int j, int start, int end, int target) {\n\t\tif (start == i || start == j)\n\t\t\tstart = start + 1;\n\t\tif (end == i || end == j)\n\t\t\tend = end - 1;\n\t\tif (start == end) {\n\t\t\treturn nums[start];\n\t\t} else if (end == start + 1 || end == start - 1) {\n\t\t\tif (Math.abs(nums[end] - target) > Math.abs(nums[start] - target)) {\n\t\t\t\treturn nums[start];\n\t\t\t} else {\n\t\t\t\treturn nums[end];\n\t\t\t}\n\t\t} else {\n\t\t\tint middle = (int) Math.floor((start + end) / 2);\n\t\t\tif (nums[middle] > target) {\n\t\t\t\tend = middle;\n\t\t\t} else {\n\t\t\t\tstart = middle;\n\t\t\t}\n\t\t\treturn oneSumCloset(nums, i, j, start, end, target);\n\t\t}\n\t}\n\tpublic int threeSumClosest(int[] nums, int target) {\n\t\tArrays.sort(nums);\n\t\tint minValue = 0;\n\t\tboolean hasMin = false;\n\t\tfor (int i = 0; i < nums.length - 2; i++) {\n\t\t\tfor (int j = i + 1; j < nums.length - 1; j++) {\n\t\t\t\tint twoSum = nums[i] + nums[j];\n\t\t\t\tint rest = target - twoSum;\n\t\t\t\tint restClost = oneSumCloset(nums, i, j, j + 1, nums.length - 1, rest);\n\t\t\t\tint newValue = restClost + twoSum;\n\t\t\t\t;\n\t\t\t\tif (!hasMin) {\n\t\t\t\t\tminValue = newValue;\n\t\t\t\t\thasMin = true;\n\t\t\t\t} else {\n\t\t\t\t\tint d1 = Math.abs(minValue - target);\n\t\t\t\t\tint d2 = Math.abs(newValue - target);\n\t\t\t\t\tif (d1 > d2) {\n\t\t\t\t\t\tminValue = newValue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn minValue;\n\t}\n}", + "js": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */\nvar threeSumClosest = function(nums, target) {\n\n\tconst oneSumCloset = (nums, i, j, start, end, target)=>{\n\t\tif(start===i||start===j) start = start+1;\n\t\tif(end===i||end===j) end = end-1;\n\t\t\n\t\tif(start===end){\n\t\t\treturn nums[start];\n\t\t}else if(end===start+1||end===start-1){\n\t\t\tif(Math.abs(nums[end]-target)>Math.abs(nums[start]-target)){\n\t\t\t\treturn nums[start];\n\t\t\t}else{\n\t\t\t\treturn nums[end];\n\t\t\t}\n\t\t}else{\n\t\t\tconst middle = Math.floor((start+end)/2);\n\t\t\tif(nums[middle]>target){\n\t\t\t\tend = middle;\n\t\t\t}else{\n\t\t\t\tstart = middle;\n\t\t\t}\n\t\t\treturn oneSumCloset(nums, i, j, start, end, target);\t\n\t\t}\n\t}\n\n nums.sort((a,b)=>a-b);\n\n let minValue;\n for(let i=0;id2){\n \t\t\t\tminValue = newValue;\n \t\t\t}\n\t\t\t}\n \t}\n }\n\n return minValue;\n};\n\nfunction main(){\n\tconst testCases = [\n\t\t[[-1,2,1,-4], 1, 2],\n\t\t[[-1,2,1,-4], -5, -4],\n\t\t[[0,2,1,-3],1,0],\n\t\t[[1,1,-1,-1,3],1,1],\n\t\t[[1,2,5,10,11],12,13],\n\t\t[\n\t\t\t[-73,-26,10,-40,-74,81,20,\n\t\t\t -52,80,32,-17,-20,19,34,-2,\n\t\t\t 94,-81,-66,-17,93,26,36,54,\n\t\t\t 40,40,32,3,77,-30,14,-28,-74,\n\t\t\t -60,-99,11,0,-31,-84,90,-51,\n\t\t\t -29,87,-67,55,6,96,9,-76,75,\n\t\t\t -44,32,89,13,46,29,66,-12,-90,\n\t\t\t 81,43,-46,54,74,22,70,-66,-43,97,93,\n\t\t\t -26,6,45,9,-64,-11,-43,-78,44,-92,98,-65,29,83,-30,35,-63,\n\t\t\t 13,-92,-9,79,95,-44,50,55,87,-69,81,-91,-57,5,-9,65,42,11,78,-4,-43,10,1,0,\n\t\t\t 50,-37,100,61,-82,-13,100,46,\n\t\t\t 0,-25,13,16,43,49,92,31,85,38,\n\t\t\t -63,6,-30,67,64,-4,-71,-74,-92,6,\n\t\t\t -50,-45,-71,-82,11,-39],\n\t\t\t299,\n\t\t\t298,\n\t\t],\n\t\t[\n\t\t\t[-21,7,-38,-13,15,30,-70,-48,-89,-11,\n\t\t\t-88,-92,-44,35,100,-86,42,41,-44,-94,\n\t\t\t-82,6,10,-61,78,35,99,24,-20,-81,76,\n\t\t\t-73,-92,-30,0,-95,46,99,20,-89,99,95,\n\t\t\t-83,-5,43,55,85,-70,73,10,90,87,71,\n\t\t\t24,78,-54,-35,4,33,52,-28,28,-66,-88,\n\t\t\t-29,-44,35,-54,-83,63,-90,-68,-31,-7,\n\t\t\t48,7,-99,-21,-99,-35,39,-12,77,-79,76,\n\t\t\t85,24,89,90,-86,88,81,94,82,43,-52,63,\n\t\t\t-55,-96,64,7,-2,32,-18,-19,25,63,-24,\n\t\t\t-40,81,-22,-30,62,90,-50,-95,33,20,19,\n\t\t\t87,-9,77,-50,61,-73,-4,-40,12,51,25,\n\t\t\t-21,91,-48,-86,-82,-38,15,-96,48,-20,\n\t\t\t-30,82,24,5,-61,8,-49,69,41,97,24,-46,\n\t\t\t-49,-71,30,84,48,97,91,-80,-65,32,52,\n\t\t\t-76,87,-82,-40,15,-35,-51,-76,92,31,\n\t\t\t-61,-22,-5,94,-66,3,-4,46,32,-13,40,\n\t\t\t-66,-13],\n\t\t\t-155,\n\t\t\t-155,\n\t\t]\n\t];\n\tfor(const testCase of testCases){\n\t\tconst v = threeSumClosest(testCase[0], testCase[1]);\n\t\tif(v===testCase[2]){\n\t\t\t// console.log(`[OK]: ${v}===${testCase[2]}`);\n\t\t}else{\n\t\t\tconsole.log(`[ERROR]: ${v}!==${testCase[2]}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n}\n\nmain();\n\n", + "python": "from typing import List\nclass Solution:\n\tdef threeSumClosest(self, nums: List[int], target: int) -> int:\n\t\tnums.sort()\n\t\tcur = 0\n\t\tclosest = nums[0] + nums[1] + nums[2]\n\t\twhile cur < len(nums) - 2:\n\t\t\tleft = cur + 1\n\t\t\tright = len(nums) - 1\n\t\t\twhile left < right:\n\t\t\t\tn = nums[cur] + nums[left] + nums[right]\n\t\t\t\tif abs(target - n) < abs(target - closest):\n\t\t\t\t\tclosest = n\n\t\t\t\tif n == target:\n\t\t\t\t\tbreak\n\t\t\t\telif n > target:\n\t\t\t\t\tt = right - 1\n\t\t\t\t\twhile (t > left and nums[t] == nums[right]):\n\t\t\t\t\t\tt -= 1\n\t\t\t\t\tright = t\n\t\t\t\telse:\n\t\t\t\t\tt = left + 1\n\t\t\t\t\twhile (t < right and nums[t] == nums[left]):\n\t\t\t\t\t\tt += 1\n\t\t\t\t\tleft = t\n\t\t\tt = cur + 1\n\t\t\twhile (t < len(nums) and nums[t] == nums[cur]):\n\t\t\t\tt += 1\n\t\t\tcur = t\n\t\treturn closest\n# %%\ns = Solution()\nprint(s.threeSumClosest(nums = [-1,2,1,-4], target = 1))", + "status": 1, + "keywords": "数组,双指针,排序", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/15/15_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/15/15_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/15/15_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/16.json b/data_backup/leetcode/16.json new file mode 100644 index 000000000..22be7aac4 --- /dev/null +++ b/data_backup/leetcode/16.json @@ -0,0 +1,24 @@ +{ + "question_id": 17, + "question_title": "电话号码的字母组合", + "difficulty": "中等", + "question_content": "

给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。

给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。

 

示例 1:

输入:digits = \"23\"
输出:
[\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]

示例 2:

输入:digits = \"\"
输出:
[]

示例 3:

输入:digits = \"2\"
输出:
[\"a\",\"b\",\"c\"]

 

提示:

    \t
  • 0 <= digits.length <= 4
  • \t
  • digits[i] 是范围 ['2', '9'] 的一个数字。
", + "topic_link": "https://bbs.csdn.net/topics/600471003", + "cpp": "class Solution\n{\npublic:\n\tvector letterCombinations(string digits)\n\t{\n\t\tvector nummap({\" \",\n\t\t\t\t\t\t\t \"\",\n\t\t\t\t\t\t\t \"abc\",\n\t\t\t\t\t\t\t \"def\",\n\t\t\t\t\t\t\t \"ghi\",\n\t\t\t\t\t\t\t \"jkl\",\n\t\t\t\t\t\t\t \"mno\",\n\t\t\t\t\t\t\t \"pqrs\",\n\t\t\t\t\t\t\t \"tuv\",\n\t\t\t\t\t\t\t \"wxyz\"});\n\t\tvector rs;\n\t\tvector empty;\n\t\tif (digits.size() == 0)\n\t\t\treturn empty;\n\t\tfor (auto d : digits)\n\t\t{\n\t\t\tif (d == '0')\n\t\t\t\treturn empty;\n\t\t\tif (d == '1')\n\t\t\t\treturn empty;\n\t\t\tauto &s = nummap[d - '0'];\n\t\t\tif (s.size() == 0)\n\t\t\t\tcontinue;\n\t\t\tif (rs.size() == 0)\n\t\t\t\tfor (auto c : s)\n\t\t\t\t{\n\t\t\t\t\tstring t;\n\t\t\t\t\tt.push_back(c);\n\t\t\t\t\trs.emplace_back(t);\n\t\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvector rn;\n\t\t\t\tfor (auto c : s)\n\t\t\t\t{\n\t\t\t\t\tfor (auto r : rs)\n\t\t\t\t\t{\n\t\t\t\t\t\tr.push_back(c);\n\t\t\t\t\t\trn.emplace_back(std::move(r));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstd::swap(rs, rn);\n\t\t\t}\n\t\t}\n\t\treturn rs;\n\t}\n};", + "java": "class Solution {\n\tpublic List letterCombinations(String digits) {\n\t\tCharacter[][] letters = { {}, {}, { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' }, { 'j', 'k', 'l' },\n\t\t\t\t{ 'm', 'n', 'o' }, { 'p', 'q', 'r', 's' }, { 't', 'u', 'v' }, { 'w', 'x', 'y', 'z' }, };\n\t\tList> combinations = new ArrayList<>();\n\t\tfor (int i = 0; i < digits.length(); i++) {\n\t\t\tCharacter d = digits.charAt(i);\n\t\t\tint index = Character.getNumericValue(d);\n\t\t\tCharacter[] letter = letters[index];\n\t\t\tSystem.out.println(d);\n\t\t\tif (i == 0) {\n\t\t\t\tfor (int j = 0; j < letter.length; j++) {\n\t\t\t\t\tList c = new ArrayList<>();\n\t\t\t\t\tc.add(letter[j]);\n\t\t\t\t\tcombinations.add(c);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tList> added = new ArrayList<>();\n\t\t\t\tfor (int j = 0; j < combinations.size(); j++) {\n\t\t\t\t\tList c = combinations.get(j);\n\t\t\t\t\tList origin_c = new ArrayList<>(c);\n\t\t\t\t\tfor (int k = 0; k < letter.length; k++) {\n\t\t\t\t\t\tCharacter l = letter[k];\n\t\t\t\t\t\tif (k == 0) {\n\t\t\t\t\t\t\tc.add(l);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tList new_c = new ArrayList<>(origin_c);\n\t\t\t\t\t\t\tnew_c.add(l);\n\t\t\t\t\t\t\tadded.add(new_c);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcombinations.addAll(added);\n\t\t\t}\n\t\t}\n\t\tList output = new ArrayList<>();\n\t\tfor (int i = 0; i < combinations.size(); i++) {\n\t\t\tList c = combinations.get(i);\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor (Character l : c) {\n\t\t\t\tsb.append(l);\n\t\t\t}\n\t\t\toutput.add(sb.toString());\n\t\t}\n\t\treturn output;\n\t}\n}", + "js": "\n/**\n * @param {string} digits\n * @return {string[]}\n */\nvar letterCombinations = function(digits) {\n const letters = [\n \t[],\n \t[],\n \t['a','b','c'],\n \t['d','e','f'],\n \t['g','h','i'],\n \t['j','k','l'],\n \t['m','n','o'],\n \t['p','q','r','s'],\n \t['t','u','v'],\n \t['w','x','y','z'],\n ];\n\n let combinations = [];\n let i=0;\n for(let d of digits){\n \tconst letter = letters[parseInt(d)];\n\t\tif(i===0){\n\t\t\tfor(let l of letter){\n\t\t\t\tcombinations.push([l]);\n\t\t\t}\t\n\t\t}else{\n\t\t\tlet added = [];\n\t\t\tfor(let c of combinations){\n\t\t\t\tlet j=0;\n\t\t\t\tlet ccc = [...c];\n\t\t\t\tfor(let l of letter){\n\t\t\t\t\tif(j===0){\n\t\t\t\t\t\tc.push(l);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tadded.push([...ccc, l]);\n\t\t\t\t\t}\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t}\t\n\t\t\tcombinations = [...combinations, ...added];\n\t\t}\n\t\ti++;\n }\n\n let output=[];\n \tfor(const c of combinations){\n \t\toutput.push(c.join(''));\n \t}\n \treturn output;\n};\n\nfunction main(){\n\tconst testCases = [\n\t\t[\"23\",[\"ad\", \"ae\", \"af\", \"bd\", \"be\", \"bf\", \"cd\", \"ce\", \"cf\"]]\n\t];\n\tfor(const testCase of testCases){\n\t\tconst v = letterCombinations(testCase[0]);\n\t\tif(JSON.stringify(v.sort())===JSON.stringify(testCase[1].sort())){\n\t\t\tconsole.log(`[OK]:${v}===${testCase[1]}`);\n\t\t}else{\n\t\t\tconsole.log(`[ERROR]:${v}===${testCase[1]}`);\n\t\t}\n\t}\n}\n\nmain();\n", + "python": "from typing import List\nclass Solution:\n\tdef letterCombinations(self, digits: str) -> List[str]:\n\t\tletters = [\n\t\t\t[],\n\t\t\t[],\n\t\t\t['a', 'b', 'c'],\n\t\t\t['d', 'e', 'f'],\n\t\t\t['g', 'h', 'i'],\n\t\t\t['j', 'k', 'l'],\n\t\t\t['m', 'n', 'o'],\n\t\t\t['p', 'q', 'r', 's'],\n\t\t\t['t', 'u', 'v'],\n\t\t\t['w', 'x', 'y', 'z'],\n\t\t]\n\t\tcombinations = []\n\t\ti = 0\n\t\tfor d in digits:\n\t\t\tletter = letters[int(d)]\n\t\t\tif i == 0:\n\t\t\t\tfor l in letter:\n\t\t\t\t\tcombinations.append([l])\n\t\t\telse:\n\t\t\t\tadded = []\n\t\t\t\tfor c in combinations:\n\t\t\t\t\tj = 0\n\t\t\t\t\torigin_c = []\n\t\t\t\t\torigin_c += c\n\t\t\t\t\tfor l in letter:\n\t\t\t\t\t\tif j == 0:\n\t\t\t\t\t\t\tc.append(l)\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\tnew_c = []\n\t\t\t\t\t\t\tnew_c += origin_c\n\t\t\t\t\t\t\tnew_c.append(l)\n\t\t\t\t\t\t\tadded.append(new_c)\n\t\t\t\t\t\tj += 1\n\t\t\t\tcombinations += added\n\t\t\ti += 1\n\t\toutput = []\n\t\tfor c in combinations:\n\t\t\toutput.append(''.join(c))\n\t\treturn output\n# %%\ns = Solution()\nprint(s.letterCombinations(digits = \"23\"))", + "status": 1, + "keywords": "哈希表,字符串,回溯", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/16/16_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/16/16_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/16/16_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/17.json b/data_backup/leetcode/17.json new file mode 100644 index 000000000..26747cc1a --- /dev/null +++ b/data_backup/leetcode/17.json @@ -0,0 +1,24 @@ +{ + "question_id": 18, + "question_title": "四数之和", + "difficulty": "中等", + "question_content": "

给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。

注意:答案中不可以包含重复的四元组。

 

示例 1:

输入:nums = [1,0,-1,0,-2,2], target = 0
输出:
[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]

示例 2:

输入:nums = [], target = 0
输出:
[]

 

提示:

    \t
  • 0 <= nums.length <= 200
  • \t
  • -109 <= nums[i] <= 109
  • \t
  • -109 <= target <= 109
", + "topic_link": "https://bbs.csdn.net/topics/600469919", + "cpp": "class Solution\n{\npublic:\n\tvector> fourSum(vector &nums, int target)\n\t{\n\t\tlong long l_target = target;\n\t\tsort(nums.begin(), nums.end());\n\t\tvector> results;\n\t\tint N = nums.size();\n\t\tfor (int i = 0; i < N - 3; i++)\n\t\t{\n\t\t\tif (i > 0 && nums[i] == nums[i - 1])\n\t\t\t\tcontinue;\n\t\t\tfor (int j = i + 1; j < N - 2; j++)\n\t\t\t{\n\t\t\t\tif (j > i + 1 && nums[j] == nums[j - 1])\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int k = j + 1, l = N - 1; k < l; k++)\n\t\t\t\t{\n\t\t\t\t\tif (k > j + 1 && nums[k] == nums[k - 1])\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\twhile (k < l &&\n\t\t\t\t\t\t (l_target - nums[i] - nums[j] - nums[k] - nums[l]) < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tl--;\n\t\t\t\t\t}\n\t\t\t\t\tif (k >= l)\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((target - nums[i] - nums[j] - nums[k] - nums[l]) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresults.emplace_back(\n\t\t\t\t\t\t\tvector({nums[i], nums[j], nums[k], nums[l]}));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n};", + "java": "class Solution {\n\tpublic List> fourSum(int[] nums, int target) {\n\t\tlong l_target = target;\n\t\tArrays.sort(nums);\n\t\tList> results = new ArrayList<>();\n\t\tint N = nums.length;\n\t\tfor (int i = 0; i < N - 3; i++) {\n\t\t\tif (i > 0 && nums[i] == nums[i - 1])\n\t\t\t\tcontinue;\n\t\t\tfor (int j = i + 1; j < N - 2; j++) {\n\t\t\t\tif (j > i + 1 && nums[j] == nums[j - 1])\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int k = j + 1, l = N - 1; k < l; k++) {\n\t\t\t\t\tif (k > j + 1 && nums[k] == nums[k - 1])\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\twhile (k < l && (l_target - nums[i] - nums[j] - nums[k] - nums[l]) < 0) {\n\t\t\t\t\t\tl--;\n\t\t\t\t\t}\n\t\t\t\t\tif (k >= l) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ((target - nums[i] - nums[j] - nums[k] - nums[l]) == 0) {\n\t\t\t\t\t\tList item = new ArrayList<>();\n\t\t\t\t\t\titem.add(nums[i]);\n\t\t\t\t\t\titem.add(nums[j]);\n\t\t\t\t\t\titem.add(nums[k]);\n\t\t\t\t\t\titem.add(nums[l]);\n\t\t\t\t\t\tresults.add(item);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n}", + "js": "/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[][]}\n */\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[][]}\n */\n var fourSum = function(nums, target) {\n nums.sort((a,b)=>a-b);\n\n let results = [];\n for(let i=0;i0&&nums[i]===nums[i-1]) continue;\n \tfor(let j=i+1;ji+1&&nums[j]===nums[j-1]) continue;\n \t\tfor(let k=j+1, l=nums.length-1;kj+1&&nums[k]===nums[k-1]) continue;\n\n\t\t\t\twhile(k=l){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif((target - nums[i] - nums[j] - nums[k] - nums[l])===0){\n\t\t\t\t\tresults.push([\n\t\t\t\t\t\tnums[i], nums[j], nums[k], nums[l]\n\t\t\t\t\t]);\n\t\t\t\t}\n \t\t}\n \t}\n }\n return results;\n};\n\nfunction main(){\n\tconst testCases =[\n\t\t[\n\t\t\t[1, 0, -1, 0, -2, 2], 0,\n\t\t\t[\n\t\t\t [-1, 0, 0, 1],\n\t\t\t [-2, -1, 1, 2],\n\t\t\t [-2, 0, 0, 2]\n\t\t\t]\n\t\t],\n\n\t\t[\n\t\t\t[-4,-3,-1,-2,-2,0,-3,0,1,3,3], 0,\n\t\t\t[\n\t\t\t\t[-3,-2,2,3],\n\t\t\t\t[-3,-1,1,3],\n\t\t\t\t[-3,0,0,3],\n\t\t\t\t[-3,0,1,2],\n\t\t\t\t[-2,-1,0,3],\n\t\t\t\t[-1,0,0,1],\n\n\t\t\t\t[-2,-1,1,2],\n\t\t\t\t[-2,0,0,2],\n\t\t\t]\n\t\t],\n\n\t\t[\n\t\t\t[-3,-2,-1,0,-3,0,1,2,3], 0,\n\t\t\t[\n\t\t\t\t[-3,-2,2,3],\n\t\t\t\t[-3,-1,1,3],\n\t\t\t\t[-3,0,0,3],\n\t\t\t\t[-3,0,1,2],\n\t\t\t\t[-2,-1,0,3],\n\t\t\t\t[-1,0,0,1],\n\n\t\t\t\t[-2,-1,1,2],\n\t\t\t\t[-2,0,0,2],\n\t\t\t]\n\t\t],\n\n\t\t[\n\t\t\t[0,1,5,0,1,5,5,-4],11,\n\t\t\t[\n\t\t\t\t[-4,5,5,5],\n\t\t\t\t[0,1,5,5]\n\t\t\t]\n\t\t],\n\n\t\t[\n\t\t\t[-489,-475,-469,-468,-467,\n\t\t\t -462,-456,-443,-439,-425,\n\t\t\t -425,-410,-401,-342,-341,\n\t\t\t -331,-323,-307,-299,-262,\n\t\t\t -254,-245,-244,-238,-229,\n\t\t\t -227,-225,-224,-221,-197,\n\t\t\t -173,-171,-160,-142,-142,\n\t\t\t -136,-134,-125,-114,-100,\n\t\t\t -86,-81,-66,-47,-37,-34,4,\n\t\t\t 7,11,34,60,76,99,104,113,\n\t\t\t 117,124,139,141,143,144,\n\t\t\t 146,157,157,178,183,185,189,\n\t\t\t 192,194,221,223,226,232,247,\n\t\t\t 249,274,281,284,293,298,319,\n\t\t\t 327,338,340,368,375,377,379,\n\t\t\t 388,390,392,446,469,480,490]\n\t\t\t, 2738\n\t\t\t, []\n\t\t]\n\t];\n\n\tfor(const testCase of testCases){\n\t\tconst v = fourSum(testCase[0], testCase[1]);\n\n\t\tconsole.log(v);\n\n\t\tif(v.length===testCase[2].length){\n\t\t\tconsole.log(`[OK]:${v.length}===${testCase[2].length}`);\n\t\t}else{\n\t\t\tconsole.log(`[ERROR]:${v.length}===${testCase[2].length}`);\n\t\t}\n\t}\n}\n\nmain();\n", + "python": "class Solution(object):\n\tdef fourSum(self, nums, target):\n\t\t\"\"\"\n\t\t:type nums: List[int]\n\t\t:type target: int\n\t\t:rtype: List[List[int]]\n\t\t\"\"\"\n\t\tnums.sort()\n\t\tresults = []\n\t\tN = len(nums)\n\t\ti = 0\n\t\twhile i < N-3:\n\t\t\tif i > 0 and nums[i] == nums[i-1]:\n\t\t\t\ti += 1\n\t\t\t\tcontinue\n\t\t\tj = i+1\n\t\t\twhile j < N-2:\n\t\t\t\tif j > i+1 and nums[j] == nums[j-1]:\n\t\t\t\t\tj += 1\n\t\t\t\t\tcontinue\n\t\t\t\tk = j+1\n\t\t\t\tl = N-1\n\t\t\t\twhile k < l:\n\t\t\t\t\tif k > j+1 and nums[k] == nums[k-1]:\n\t\t\t\t\t\tk += 1\n\t\t\t\t\t\tcontinue\n\t\t\t\t\twhile k < l and (target - nums[i] - nums[j] - nums[k] - nums[l]) < 0:\n\t\t\t\t\t\tl -= 1\n\t\t\t\t\tif k >= l:\n\t\t\t\t\t\tbreak\n\t\t\t\t\tif target == nums[i] + nums[j] + nums[k] + nums[l]:\n\t\t\t\t\t\tresults.append([\n\t\t\t\t\t\t\tnums[i],\n\t\t\t\t\t\t\tnums[j],\n\t\t\t\t\t\t\tnums[k],\n\t\t\t\t\t\t\tnums[l]\n\t\t\t\t\t\t])\n\t\t\t\t\tk += 1\n\t\t\t\tj += 1\n\t\t\ti += 1\n\t\treturn results\n# %%\ns = Solution()\nprint(s.fourSum(nums = [1,0,-1,0,-2,2], target = 0))", + "status": 1, + "keywords": "数组,双指针,排序", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/17/17_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/17/17_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/17/17_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/18.json b/data_backup/leetcode/18.json new file mode 100644 index 000000000..689aafc8b --- /dev/null +++ b/data_backup/leetcode/18.json @@ -0,0 +1,24 @@ +{ + "question_id": 19, + "question_title": "删除链表的倒数第 N 个结点", + "difficulty": "中等", + "question_content": "

给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。

进阶:你能尝试使用一趟扫描实现吗?

 

示例 1:

\"\"
输入:head = [1,2,3,4,5], n = 2
输出:
[1,2,3,5]

示例 2:

输入:head = [1], n = 1
输出:
[]

示例 3:

输入:head = [1,2], n = 1
输出:
[1]

 

提示:

    \t
  • 链表中结点的数目为 sz
  • \t
  • 1 <= sz <= 30
  • \t
  • 0 <= Node.val <= 100
  • \t
  • 1 <= n <= sz
", + "topic_link": "https://bbs.csdn.net/topics/600469818", + "cpp": "struct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode() : val(0), next(nullptr) {}\n\tListNode(int x) : val(x), next(nullptr) {}\n\tListNode(int x, ListNode *next) : val(x), next(next) {}\n};\n#include \nclass Solution\n{\npublic:\n\tListNode *removeNthFromEnd(ListNode *head, int n)\n\t{\n\t\tListNode empty_node(0, head);\n\t\tListNode *p = &empty_node;\n\t\tstd::vector pv;\n\t\twhile (p != nullptr)\n\t\t{\n\t\t\tpv.push_back(p);\n\t\t\tp = p->next;\n\t\t}\n\t\tp = pv[pv.size() - 1 - n];\n\t\tp->next = p->next->next;\n\t\treturn empty_node.next;\n\t}\n};", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode() {\n\t}\n\tListNode(int val) {\n\t\tthis.val = val;\n\t}\n\tListNode(int val, ListNode next) {\n\t\tthis.val = val;\n\t\tthis.next = next;\n\t}\n}\nclass Solution {\n\tpublic ListNode removeNthFromEnd(ListNode head, int n) {\n\t\tListNode v = new ListNode(0, head);\n\t\tListNode handle = v;\n\t\tList index = new ArrayList<>();\n\t\twhile (v != null) {\n\t\t\tindex.add(v);\n\t\t\tv = v.next;\n\t\t}\n\t\tint pre = index.size() - n - 1;\n\t\tint next = index.size() - n + 1;\n\t\tindex.get(pre).next = next >= 0 && next < index.size() ? index.get(next) : null;\n\t\treturn handle.next;\n\t}\n}", + "js": "/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n * this.val = (val===undefined ? 0 : val)\n * this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @param {number} n\n * @return {ListNode}\n */\n var removeNthFromEnd = function(head, n) {\n let v = {val:0, next: head};\n\tlet handle = v;\n\tlet index = [];\n\twhile(v!=null){\n\t\tindex.push(v);\n\t\tv = v.next;\n\t}\n\n\tconst pre = index.length-n-1;\n\tconst next = index.length-n+1;\n\tindex[pre].next = index[next]===undefined?null:index[next];\n\t\n return handle.next;\n};\n\nfunction main(){\n\tconst testCases = [\n\t\t[\n\t\t\t{val:1},\n\t\t\t1,\n\t\t\tundefined\n\t\t],\n\n\t\t[\n\t\t\t{val:1,next:{val:1}},\n\t\t\t2,\n\t\t\t{val:1}\n\t\t],\n\n\t\t[\n\t\t\t{val:1,next:{val:2,next:{val:3,next:{val:4,next:{val:5}}}}},\n\t\t\t2,\n\t\t\t{val:1,next:{val:2,next:{val:3,next:{val:5}}}},\n\t\t]\n\t];\t\n\tfor(const testCase of testCases){\n\t\tconst output = removeNthFromEnd(testCase[0], testCase[1]);\n\t\tif(JSON.stringify(output)===JSON.stringify(testCase[2])){\n\t\t\tconsole.log(`[OK]`);\n\t\t}else{\n\t\t\tconsole.log(`[ERROR]`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n}\n\nmain();\n", + "python": "class ListNode:\n\tdef __init__(self, val=0, next=None):\n\t\tself.val = val\n\t\tself.next = next\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution:\n\tdef removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:\n\t\tv = ListNode(0, head)\n\t\thandle = v\n\t\tindex = []\n\t\twhile v is not None:\n\t\t\tindex.append(v)\n\t\t\tv = v.next\n\t\tpre = len(index)-n-1\n\t\tnext = len(index)-n+1\n\t\tindex[pre].next = index[next] if next >= 0 and next < len(\n\t\t\tindex) else None\n\t\treturn handle.next\n# %%\nl = LinkList()\nlist1 = [1,2,3,4,5]\nhead = l.initList(list1)\nn = 2\ns = Solution()\nprint(l.convert_list(s.removeNthFromEnd(head, n)))", + "status": 1, + "keywords": "链表,双指针", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/18/18_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/18/18_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/18/18_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/19.json b/data_backup/leetcode/19.json new file mode 100644 index 000000000..c031c2f2b --- /dev/null +++ b/data_backup/leetcode/19.json @@ -0,0 +1,24 @@ +{ + "question_id": 20, + "question_title": "有效的括号", + "difficulty": "简单", + "question_content": "

给定一个只包括 '('')''{''}''['']' 的字符串 s ,判断字符串是否有效。

有效字符串需满足:

    \t
  1. 左括号必须用相同类型的右括号闭合。
  2. \t
  3. 左括号必须以正确的顺序闭合。

 

示例 1:

输入:s = \"()\"
输出:
true

示例 2:

输入:s = \"()[]{}\"
输出:
true

示例 3:

输入:s = \"(]\"
输出:
false

示例 4:

输入:s = \"([)]\"
输出:
false

示例 5:

输入:s = \"{[]}\"
输出:
true

 

提示:

    \t
  • 1 <= s.length <= 104
  • \t
  • s 仅由括号 '()[]{}' 组成
", + "topic_link": "https://bbs.csdn.net/topics/600470114", + "cpp": "#include \nchar ascii_tab[128];\nclass Solution\n{\npublic:\n\tbool isValid(string s)\n\t{\n\t\tif (s.size() == 0)\n\t\t\treturn true;\n\t\tstd::stack st;\n\t\tascii_tab['('] = 11;\n\t\tascii_tab['{'] = 12;\n\t\tascii_tab['['] = 13;\n\t\tascii_tab[')'] = 21;\n\t\tascii_tab['}'] = 22;\n\t\tascii_tab[']'] = 23;\n\t\tfor (auto c : s)\n\t\t{\n\t\t\tchar n = ascii_tab[c];\n\t\t\tif (n < 20)\n\t\t\t\tst.push(n);\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (st.empty())\n\t\t\t\t\treturn false;\n\t\t\t\tif (n != st.top() + 10)\n\t\t\t\t\treturn false;\n\t\t\t\tst.pop();\n\t\t\t}\n\t\t}\n\t\tif (st.empty())\n\t\t\treturn true;\n\t\treturn false;\n\t}\n};", + "java": "class Solution {\n\tpublic boolean isValid(String s) {\n\t\tchar[] parentheses = { '(', '[', '{', ')', ']', '}' };\n\t\tint i = 0;\n\t\tchar c;\n\t\tint[] sum = { 0, 0, 0 };\n\t\tStack top = new Stack();\n\t\twhile (i < s.length()) {\n\t\t\tc = s.charAt(i);\n\t\t\tfor (int j = 0; j <= 2; j++) {\n\t\t\t\tif (c == parentheses[j]) {\n\t\t\t\t\ttop.push(j);\n\t\t\t\t\tsum[j]++;\n\t\t\t\t} else if (c == parentheses[j + 3]) {\n\t\t\t\t\tif (top.size() == 0 || top.peek() != j) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\ttop.pop();\n\t\t\t\t\tsum[j]--;\n\t\t\t\t} else {\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tfor (int j = 0; j <= 2; j++) {\n\t\t\tif (sum[j] != 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}", + "js": "/**\n * @param {string} s\n * @return {boolean}\n */\nvar isValid = function(s) {\n \tlet parentheses = [\n \t\t'(', '[', '{', \n \t\t')', ']', '}'\n \t];\n \tlet i=0;\n \tlet c;\n \tlet sum = [0,0,0]\n \tlet top = [];\n \twhile(i bool:\n\t\tparentheses = [\n\t\t\t'(', '[', '{',\n\t\t\t')', ']', '}'\n\t\t]\n\t\ti = 0\n\t\tsum = [0, 0, 0]\n\t\ttop = []\n\t\twhile i < len(s):\n\t\t\tc = s[i]\n\t\t\tj = 0\n\t\t\twhile j <= 2:\n\t\t\t\tif c == parentheses[j]:\n\t\t\t\t\ttop.append(j)\n\t\t\t\t\tsum[j] += 1\n\t\t\t\telif c == parentheses[j+3]:\n\t\t\t\t\tif len(top) == 0 or top[len(top)-1] != j:\n\t\t\t\t\t\treturn False\n\t\t\t\t\ttop.pop()\n\t\t\t\t\tsum[j] -= 1\n\t\t\t\tj += 1\n\t\t\ti += 1\n\t\tif sum[0] != 0 or sum[1] != 0 or sum[2] != 0:\n\t\t\treturn False\n\t\telse:\n\t\t\treturn True\n# %%\ns = Solution()\nprint(s.isValid(s = \"()[]{}\"))", + "status": 1, + "keywords": "栈,字符串", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/19/19_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/19/19_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/19/19_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/2.json b/data_backup/leetcode/2.json new file mode 100644 index 000000000..de9dedd56 --- /dev/null +++ b/data_backup/leetcode/2.json @@ -0,0 +1,24 @@ +{ + "question_id": 3, + "question_title": "无重复字符的最长子串", + "difficulty": "中等", + "question_content": "

给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。

 

示例 1:

输入: s = \"abcabcbb\"
输出:
3
解释:
因为无重复字符的最长子串是 \"abc\",所以其长度为 3。

示例 2:

输入: s = \"bbbbb\"
输出:
1
解释:
因为无重复字符的最长子串是 \"b\",所以其长度为 1。

示例 3:

输入: s = \"pwwkew\"
输出:
3
解释:
因为无重复字符的最长子串是 \"wke\",所以其长度为 3。 \n请注意,你的答案必须是 子串 的长度,\"pwke\" 是一个子序列,不是子串。

示例 4:

输入: s = \"\"
输出:
0

 

提示:

    \t
  • 0 <= s.length <= 5 * 104
  • \t
  • s 由英文字母、数字、符号和空格组成
", + "topic_link": "https://bbs.csdn.net/topics/600471011", + "cpp": "int hset[128];\nint lengthOfLongestSubstring(char *s)\n{\n\tint i = 0, j = 0;\n\tint m = 0;\n\tmemset(hset, 0, sizeof hset);\n\tfor (; s[j]; j++)\n\t{\n\t\ti = hset[s[j]] > i ? hset[s[j]] : i;\n\t\tm = m > j - i + 1 ? m : j - i + 1;\n\t\thset[s[j]] = j + 1;\n\t}\n\treturn m;\n}", + "java": "class Solution {\n\tpublic int lengthOfLongestSubstring(String s) {\n\t\tint i = 0;\n\t\tint j = 0;\n\t\tint m = 0;\n\t\tMap hset = new HashMap<>();\n\t\tfor (; j < s.length(); j++) {\n\t\t\tint code = s.codePointAt(j);\n\t\t\tInteger o = hset.get(code);\n\t\t\tif (o != null && o > i) {\n\t\t\t\ti = o;\n\t\t\t}\n\t\t\tm = m > j - i + 1 ? m : j - i + 1;\n\t\t\thset.put(code, j + 1);\n\t\t}\n\t\treturn m;\n\t}\n}", + "js": "\n/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstring = function(s) {\n let i = 0;\n let j = 0;\n let m = 0;\n let hset = {};\n for (;s[j];j++) {\n i = hset[s[j]] > i ? hset[s[j]] : i;\n m = m > j - i + 1 ? m : j - i + 1;\n hset[s[j]] = j + 1;\n }\n return m;\n};\n", + "python": "class Solution:\n\tdef lengthOfLongestSubstring(self, s: str) -> int:\n\t\ti = 0\n\t\tj = 0\n\t\tm = 0\n\t\thset = {}\n\t\twhile j < len(s):\n\t\t\tchar = s[j]\n\t\t\tindex = hset.get(char)\n\t\t\tif index is not None and index > i:\n\t\t\t\ti = index\n\t\t\tm = m if m > j - i + 1 else j - i + 1\n\t\t\thset[char] = j + 1\n\t\t\tj += 1\n\t\treturn m\n# %%\ns = Solution()\nprint(s.lengthOfLongestSubstring('abcabcbb'))", + "status": 1, + "keywords": "哈希表,字符串,滑动窗口", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/2/2_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/2/2_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/2/2_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/20.json b/data_backup/leetcode/20.json new file mode 100644 index 000000000..fcd83de39 --- /dev/null +++ b/data_backup/leetcode/20.json @@ -0,0 +1,24 @@ +{ + "question_id": 21, + "question_title": "合并两个有序链表", + "difficulty": "简单", + "question_content": "

将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 

 

示例 1:

\"\"
输入:l1 = [1,2,4], l2 = [1,3,4]
输出:
[1,1,2,3,4,4]

示例 2:

输入:l1 = [], l2 = []
输出:
[]

示例 3:

输入:l1 = [], l2 = [0]
输出:
[0]

 

提示:

    \t
  • 两个链表的节点数目范围是 [0, 50]
  • \t
  • -100 <= Node.val <= 100
  • \t
  • l1l2 均按 非递减顺序 排列
", + "topic_link": "https://bbs.csdn.net/topics/600469819", + "cpp": "struct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode(int x) : val(x), next(NULL) {}\n};\nclass Solution\n{\npublic:\n\tListNode *mergeTwoLists(ListNode *l1, ListNode *l2)\n\t{\n\t\tListNode h(0, nullptr);\n\t\tListNode *p = &h;\n\t\twhile (l1 && l2)\n\t\t{\n\t\t\tListNode **t;\n\t\t\tif (l1->val < l2->val)\n\t\t\t\tt = &l1;\n\t\t\telse\n\t\t\t\tt = &l2;\n\t\t\tp->next = *t;\n\t\t\tp = *t;\n\t\t\t*t = (*t)->next;\n\t\t}\n\t\tif (l1)\n\t\t\tp->next = l1;\n\t\telse\n\t\t\tp->next = l2;\n\t\treturn h.next;\n\t}\n};", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode() {\n\t}\n\tListNode(int val) {\n\t\tthis.val = val;\n\t}\n\tListNode(int val, ListNode next) {\n\t\tthis.val = val;\n\t\tthis.next = next;\n\t}\n}\nclass Solution {\n\tpublic ListNode mergeTwoLists(ListNode l1, ListNode l2) {\n\t\tListNode h = new ListNode(0, null);\n\t\tListNode p = h;\n\t\twhile (l1 != null && l2 != null) {\n\t\t\tif (l1.val < l2.val) {\n\t\t\t\tp.next = l1;\n\t\t\t\tp = l1;\n\t\t\t\tl1 = l1.next;\n\t\t\t} else {\n\t\t\t\tp.next = l2;\n\t\t\t\tp = l2;\n\t\t\t\tl2 = l2.next;\n\t\t\t}\n\t\t}\n\t\tif (l1 != null) {\n\t\t\tp.next = l1;\n\t\t} else {\n\t\t\tp.next = l2;\n\t\t}\n\t\treturn h.next;\n\t}\n}", + "js": "/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n * this.val = val;\n * this.next = null;\n * }\n */\n/**\n * @param {ListNode} l1\n * @param {ListNode} l2\n * @return {ListNode}\n */\nvar mergeTwoLists = function(l1, l2) {\n let v1=l1;\n let v2=l2;\n let v1pre = {val:0,next:v1};\n let root = v1pre;\n let d;\n\n const slide = (pre, node, target)=>{\n\n \tif(node.val>target){\n \t\treturn [1, pre, node];\n \t}\n\n \twhile(node.next!=null){\n \t\tif(node.next.val>=target){\n \t\t\treturn [0, pre, node]\n \t\t}else{\n \t\t\tnode = node.next;\n \t\t\tpre = pre.next;\n \t\t}\n \t}\n \treturn [0, pre, node];\n }\n\n while(true){\n \tif(v1!=null&&v2!=null){\n \t\t[d, v1pre, v1] = slide(v1pre, v1, v2.val);\n \t\tif(d===0){\n \t\t\tv1.next = {\n\t \t\t\tval: v2.val,\n\t \t\t\tnext: v1.next\n\t \t\t};\n \t\t}else{\n \t\t\tv1pre.next = {\n\t \t\t\tval: v2.val,\n\t \t\t\tnext: v1\n\t \t\t};\n\t \t\tv1 = v1pre.next;\n \t\t}\n \t\t\n \t\tv2=v2.next;\n \t}else if(v1!=null&&v2==null){\n \t\tbreak;\n \t}else if(v1==null&&v2!=null){\n \t\tv1pre.next=v2;\n \t\tbreak;\n \t}else{\n \t\tbreak;\n \t}\n }\n\n // console.log(v1pre.next);\n\n return root.next;\n};\n\nfunction main(){\n\tconst testCases = [\n\t\t[\n\t\t\tnull,\n\t\t\t{\"val\":0,\"next\":null},\n\t\t\t{\"val\":0,\"next\":null},\n\t\t],\n\n\t\t[\n\t\t\t{\"val\":2,\"next\":null},\n\t\t\t{\"val\":1,\"next\":null},\n\t\t\t{val:1,next:{val:2,next:null}}\n\t\t],\n\n\t\t[\n\t\t\t{\"val\":2,\"next\":null},\n\t\t\t{\"val\":2,\"next\":{val:1}},\n\t\t\t{val:1,next:{val:2,next:{val:2,next:null}}}\n\t\t],\n\n\t\t[\n\t\t\t{val:1,next:{val:2,next:{val:4}}},\n\t\t\t{val:1,next:{val:3,next:{val:4}}},\n\t\t\t{val:1,next:{val:1,next:{val:2,next:{val:3,next:{val:4,next:{val:4}}}}}}\n\t\t],\n\n\t\t[\n\t\t\t{val: 5},\n\t\t\t{val:1,next:{val:2,next:{val:4}}},\n\t\t\t{val:1,next:{val:2,next:{val:4,next:{val:5}}}},\n\t\t]\n\t];\n\tfor(const testCase of testCases){\n\t\tconst v = mergeTwoLists(testCase[0], testCase[1]);\n\t\tif(JSON.stringify(v)===JSON.stringify(testCase[2])){\n\t\t\tconsole.log(`[OK]`);\n\t\t}else{\n\t\t\tconsole.log(`[ERROR]`);\n\t\t}\n\t}\n}\n\nmain();\n\n\n\n\n\n", + "python": "class ListNode:\n\tdef __init__(self, val=0, next=None):\n\t\tself.val = val\n\t\tself.next = next\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution:\n\tdef mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:\n\t\th = ListNode(0, None)\n\t\tp = h\n\t\twhile l1 and l2:\n\t\t\tif l1.val < l2.val:\n\t\t\t\tp.next = l1\n\t\t\t\tp = l1\n\t\t\t\tl1 = l1.next\n\t\t\telse:\n\t\t\t\tp.next = l2\n\t\t\t\tp = l2\n\t\t\t\tl2 = l2.next\n\t\tif l1:\n\t\t\tp.next = l1\n\t\telse:\n\t\t\tp.next = l2\n\t\treturn h.next\n# %%\nl = LinkList()\nlist1 = [1,2,4]\nlist2 = [1,3,4]\nl1 = l.initList(list1)\nl2 = l.initList(list2)\ns = Solution()\nprint(l.convert_list(s.mergeTwoLists(l1, l2)))", + "status": 1, + "keywords": "递归,链表", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/20/20_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/20/20_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/20/20_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/21.json b/data_backup/leetcode/21.json new file mode 100644 index 000000000..f94a8f147 --- /dev/null +++ b/data_backup/leetcode/21.json @@ -0,0 +1,24 @@ +{ + "question_id": 22, + "question_title": "括号生成", + "difficulty": "中等", + "question_content": "

数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。

 

示例 1:

输入:n = 3
输出:
[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]

示例 2:

输入:n = 1
输出:
[\"()\"]

 

提示:

    \t
  • 1 <= n <= 8
", + "topic_link": "https://bbs.csdn.net/topics/600470115", + "cpp": "class Solution\n{\npublic:\n\tvoid gen(string &p, int lc, int rc, vector &r, int n)\n\t{\n\t\tif (lc > n)\n\t\t\treturn;\n\t\tif (lc == n && rc == n)\n\t\t{\n\t\t\tr.push_back(p);\n\t\t\treturn;\n\t\t}\n\t\tp.push_back('(');\n\t\tlc++;\n\t\tgen(p, lc, rc, r, n);\n\t\tp.pop_back();\n\t\tlc--;\n\t\tif (lc > rc)\n\t\t{\n\t\t\tp.push_back(')');\n\t\t\trc++;\n\t\t\tgen(p, lc, rc, r, n);\n\t\t\tp.pop_back();\n\t\t\trc--;\n\t\t}\n\t}\n\tvector generateParenthesis(int n)\n\t{\n\t\tstring p;\n\t\tint lc = 0, rc = 0;\n\t\tvector r;\n\t\tgen(p, lc, rc, r, n);\n\t\treturn r;\n\t}\n};", + "java": "class Solution {\n\tvoid gen(Stack p, int lc, int rc, List r, int n) {\n\t\tif (lc > n) {\n\t\t\treturn;\n\t\t}\n\t\tif (lc == n && rc == n) {\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor (String l : p) {\n\t\t\t\tsb.append(l);\n\t\t\t}\n\t\t\tr.add(sb.toString());\n\t\t}\n\t\tp.push(\"(\");\n\t\tlc++;\n\t\tgen(p, lc, rc, r, n);\n\t\tp.pop();\n\t\tlc--;\n\t\tif (lc > rc) {\n\t\t\tp.push(\")\");\n\t\t\trc++;\n\t\t\tgen(p, lc, rc, r, n);\n\t\t\tp.pop();\n\t\t\trc--;\n\t\t}\n\t}\n\tpublic List generateParenthesis(int n) {\n\t\tList results = new ArrayList();\n\t\tStack p = new Stack();\n\t\tgen(p, 0, 0, results, n);\n\t\treturn results;\n\t}\n}", + "js": "/**\n * @param {number} n\n * @return {string[]}\n */\n/**\n * @param {number} n\n * @return {string[]}\n */\n var generateParenthesis = function(n) {\n const gen = (p,lc,rc,r,n)=>{\n if(lc>n){\n return;\n }\n if(lc==n&&rc==n){\n r.push(p.join(''));\n }\n \n p.push('(');\n lc++;\n gen(p,lc,rc,r,n);\n \n p.pop();\n lc--;\n if(lc>rc){\n p.push(')');\n rc++;\n gen(p,lc,rc,r,n);\n \n p.pop();\n rc--;\n }\n }\n \n results = []\n gen([],0,0,results, n);\n return results;\n};\n\nfunction main(){\n\tconst testCases = [\n\t\t// [\n\t\t// \t3,\n\t\t// \t[\n\t\t// \t \"((()))\",\n\t\t// \t \"(()())\",\n\t\t// \t \"(())()\",\n\t\t// \t \"()(())\",\n\t\t// \t \"()()()\"\n\t\t// \t]\n\t\t// ],\n\t\t\n\t\t// [\n\t\t// \t4,\n\t\t// \t[\n\t\t// \t\t\"(((())))\",\n\t\t// \t\t\"((()))()\",\n\t\t// \t\t\"()((()))\",\n\t\t// \t\t\"(())(())\",\n\t\t// \t\t\"((()()))\",\n\t\t// \t\t\"((())())\",\n\t\t// \t\t\"(()(()))\",\n\t\t// \t\t\"(()()())\",\n\t\t// \t\t\"(()())()\",\n\t\t// \t\t\"(())()()\",\n\t\t// \t\t\"()(()())\",\n\t\t// \t\t\"()(())()\",\n\t\t// \t\t\"()()(())\",\n\t\t// \t\t\"()()()()\"\n\t\t// \t],\n\t\t// ],\n\t\t[\n\t\t\t10\n\t\t]\n\t];\n\tfor(const testCase of testCases){\n\t\tconst v = generateParenthesis(testCase[0]);\n\t\tconsole.log(v);\n\t}\n}\n\nmain();\n", + "python": "from typing import List\nclass Solution:\n\tdef generateParenthesis(self, n: int) -> List[str]:\n\t\tdef gen(p, lc, rc, r, n):\n\t\t\tif lc > n:\n\t\t\t\treturn\n\t\t\tif lc == n and rc == n:\n\t\t\t\tr.append(''.join(p))\n\t\t\tp.append('(')\n\t\t\tlc += 1\n\t\t\tgen(p, lc, rc, r, n)\n\t\t\tp.pop()\n\t\t\tlc -= 1\n\t\t\tif lc > rc:\n\t\t\t\tp.append(')')\n\t\t\t\trc += 1\n\t\t\t\tgen(p, lc, rc, r, n)\n\t\t\t\tp.pop()\n\t\t\t\trc -= 1\n\t\tresults = []\n\t\tgen([], 0, 0, results, n)\n\t\treturn results\n# %%\ns = Solution()\nprint(s.generateParenthesis(n = 3))", + "status": 1, + "keywords": "字符串,动态规划,回溯", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/21/21_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/21/21_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/21/21_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/22.json b/data_backup/leetcode/22.json new file mode 100644 index 000000000..847bf09e5 --- /dev/null +++ b/data_backup/leetcode/22.json @@ -0,0 +1,24 @@ +{ + "question_id": 23, + "question_title": "合并K个升序链表", + "difficulty": "困难", + "question_content": "

给你一个链表数组,每个链表都已经按升序排列。

请你将所有链表合并到一个升序链表中,返回合并后的链表。

 

示例 1:

输入:lists = [[1,4,5],[1,3,4],[2,6]]
输出:
[1,1,2,3,4,4,5,6]
解释:
链表数组如下:[ 1->4->5, 1->3->4, 2->6]将它们合并到一个有序链表中得到。1->1->2->3->4->4->5->6

示例 2:

输入:lists = []
输出:
[]

示例 3:

输入:lists = [[]]
输出:
[]

 

提示:

    \t
  • k == lists.length
  • \t
  • 0 <= k <= 10^4
  • \t
  • 0 <= lists[i].length <= 500
  • \t
  • -10^4 <= lists[i][j] <= 10^4
  • \t
  • lists[i]升序 排列
  • \t
  • lists[i].length 的总和不超过 10^4
", + "topic_link": "https://bbs.csdn.net/topics/600470116", + "cpp": "#include \nusing namespace std;\nstruct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode() : val(0), next(nullptr) {}\n\tListNode(int x) : val(x), next(nullptr) {}\n\tListNode(int x, ListNode *next) : val(x), next(next) {}\n};\nclass Solution\n{\npublic:\n\tListNode *mergeKLists(vector &lists)\n\t{\n\t\tauto cmp = [](struct ListNode *n1, struct ListNode *n2)\n\t\t{\n\t\t\treturn n1->val > n2->val;\n\t\t} priority_queue, decltype(cmp)>\n\t\t\tqueue(cmp);\n\t\tfor (int i = 0; i < lists.size(); i++)\n\t\t{\n\t\t\tif (lists[i] != nullptr)\n\t\t\t{\n\t\t\t\tqueue.push(lists[i]);\n\t\t\t}\n\t\t}\n\t\tstruct ListNode dummy, *p = &dummy;\n\t\t;\n\t\twhile (!queue.empty())\n\t\t{\n\t\t\tListNode *node = queue.top();\n\t\t\tqueue.pop();\n\t\t\tp->next = node;\n\t\t\tp = node;\n\t\t\tif (node->next != nullptr)\n\t\t\t{\n\t\t\t\tqueue.push(node->next);\n\t\t\t}\n\t\t}\n\t\treturn dummy.next;\n\t}\n};", + "java": "\npublic class ListNode {\n\tint val;\n\tListNode next;\n\n\tListNode() {\n\t}\n\n\tListNode(int val) {\n\t\tthis.val = val;\n\t}\n\n\tListNode(int val, ListNode next) {\n\t\tthis.val = val;\n\t\tthis.next = next;\n\t}\n}\n\nclass Solution {\n\tpublic ListNode mergeKLists(ListNode[] lists) {\n\t\tif (lists.length == 0)\n\t\t\treturn null;\n\n\t\treturn merge(lists, 0, lists.length - 1);\n\t}\n\n\tpublic ListNode merge(ListNode[] lists, int low, int high) {\n\t\tif (high - low == 0)\n\t\t\treturn lists[low];\n\t\telse if (high - low == 1)\n\t\t\treturn mergeTwoLists(lists[low], lists[high]);\n\t\telse {\n\t\t\tint mid = (low + high) / 2;\n\t\t\tListNode tmp1 = merge(lists, low, mid);\n\t\t\tListNode tmp2 = merge(lists, mid + 1, high);\n\t\t\treturn mergeTwoLists(tmp1, tmp2);\n\t\t}\n\t}\n\n\tpublic ListNode mergeTwoLists(ListNode l1, ListNode l2) {\n\t\tListNode head = new ListNode();\n\t\tListNode p = head;\n\t\twhile (l1 != null && l2 != null) {\n\t\t\tif (l1.val > l2.val) {\n\t\t\t\tp.next = l2;\n\t\t\t\tl2 = l2.next;\n\t\t\t\tp = p.next;\n\t\t\t} else {\n\t\t\t\tp.next = l1;\n\t\t\t\tl1 = l1.next;\n\t\t\t\tp = p.next;\n\t\t\t}\n\t\t}\n\t\tif (l1 != null)\n\t\t\tp.next = l1;\n\t\tif (l2 != null)\n\t\t\tp.next = l2;\n\t\treturn head.next;\n\t}\n}\n", + "js": "", + "python": "from typing import List\nclass ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef mergeKLists(self, lists):\n\t\tif lists is None:\n\t\t\treturn None\n\t\telif len(lists) == 0:\n\t\t\treturn None\n\t\treturn self.mergeK(lists, 0, len(lists) - 1)\n\tdef mergeK(self, lists, low, high):\n\t\tif low == high:\n\t\t\treturn lists[int(low)]\n\t\telif low + 1 == high:\n\t\t\treturn self.mergeTwolists(lists[int(low)], lists[int(high)])\n\t\tmid = (low + high) / 2\n\t\treturn self.mergeTwolists(self.mergeK(lists, low, mid), self.mergeK(lists, mid + 1, high))\n\tdef mergeTwolists(self, l1, l2):\n\t\tl = LinkList()\n\t\tif type(l1) == list:\t\n\t\t\tl1 = l.initList(l1)\n\t\tif type(l2) == list:\t\n\t\t\tl2 = l.initList(l2)\n\t\tif l1 is None:\n\t\t\treturn l2\n\t\tif l2 is None:\n\t\t\treturn l1\n\t\thead = curr = ListNode(-1)\n\t\twhile l1 is not None and l2 is not None:\n\t\t\tif l1.val <= l2.val:\n\t\t\t\tcurr.next = l1\n\t\t\t\tl1 = l1.next\n\t\t\telse:\n\t\t\t\tcurr.next = l2\n\t\t\t\tl2 = l2.next\n\t\t\tcurr = curr.next\n\t\tif l1 is not None:\n\t\t\tcurr.next = l1\n\t\tif l2 is not None:\n\t\t\tcurr.next = l2\n\t\treturn head.next\n# %%\nl = LinkList()\nlist1 = [[1,4,5],[1,3,4],[2,6]]\ns = Solution()\nprint(l.convert_list(s.mergeKLists(list1)))", + "status": 1, + "keywords": "链表,分治,堆(优先队列),归并排序", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/22/22_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/22/22_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/22/22_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/23.json b/data_backup/leetcode/23.json new file mode 100644 index 000000000..2fe660f6b --- /dev/null +++ b/data_backup/leetcode/23.json @@ -0,0 +1,24 @@ +{ + "question_id": 24, + "question_title": "两两交换链表中的节点", + "difficulty": "中等", + "question_content": "

给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。

你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。

 

示例 1:

\"\"
输入:head = [1,2,3,4]
输出:
[2,1,4,3]

示例 2:

输入:head = []
输出:
[]

示例 3:

输入:head = [1]
输出:
[1]

 

提示:

    \t
  • 链表中节点的数目在范围 [0, 100]
  • \t
  • 0 <= Node.val <= 100

 

进阶:你能在不修改链表节点值的情况下解决这个问题吗?(也就是说,仅修改节点本身。)

", + "topic_link": "https://bbs.csdn.net/topics/600470117", + "cpp": "#include \nusing namespace std;\nstruct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode() : val(0), next(nullptr) {}\n\tListNode(int x) : val(x), next(nullptr) {}\n\tListNode(int x, ListNode *next) : val(x), next(next) {}\n};\nclass Solution\n{\npublic:\n\tListNode *swapPairs(ListNode *head)\n\t{\n\t\tstruct ListNode dummy, *prev = &dummy, *p = head;\n\t\tdummy.next = head;\n\t\twhile (p != nullptr && p->next != nullptr)\n\t\t{\n\t\t\tstruct ListNode *q = p->next;\n\t\t\tp->next = q->next;\n\t\t\tq->next = prev->next;\n\t\t\tprev->next = q;\n\t\t\tprev = p;\n\t\t\tp = p->next;\n\t\t}\n\t\treturn dummy.next;\n\t}\n};", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode(int x) {\n\t\tval = x;\n\t}\n}\nclass Solution {\n\tpublic ListNode swapPairs(ListNode head) {\n\t\tListNode list1 = new ListNode(0);\n\t\tlist1.next = head;\n\t\tListNode list2 = list1;\n\t\twhile (head != null && head.next != null) {\n\t\t\tlist2.next = head.next;\n\t\t\thead.next = list2.next.next;\n\t\t\tlist2.next.next = head;\n\t\t\tlist2 = list2.next.next;\n\t\t\thead = list2.next;\n\t\t}\n\t\treturn list1.next;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef swapPairs(self, head):\n\t\tdummyHead = ListNode(-1)\n\t\tdummyHead.next = head\n\t\tprev, p = dummyHead, head\n\t\twhile p != None and p.next != None:\n\t\t\tq, r = p.next, p.next.next\n\t\t\tprev.next = q\n\t\t\tq.next = p\n\t\t\tp.next = r\n\t\t\tprev = p\n\t\t\tp = r\n\t\treturn dummyHead.next\n# %%\nl = LinkList()\nhead = [1,2,3,4]\nl1 = l.initList(head)\ns = Solution()\nprint(l.convert_list(s.swapPairs(l1)))", + "status": 1, + "keywords": "递归,链表", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/FaustoPatton/article/details/82993032" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/23/23_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/23/23_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/23/23_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/24.json b/data_backup/leetcode/24.json new file mode 100644 index 000000000..836c6d21e --- /dev/null +++ b/data_backup/leetcode/24.json @@ -0,0 +1,24 @@ +{ + "question_id": 25, + "question_title": "K 个一组翻转链表", + "difficulty": "困难", + "question_content": "

给你一个链表,每 个节点一组进行翻转,请你返回翻转后的链表。

是一个正整数,它的值小于或等于链表的长度。

如果节点总数不是 的整数倍,那么请将最后剩余的节点保持原有顺序。

进阶:

    \t
  • 你可以设计一个只使用常数额外空间的算法来解决此问题吗?
  • \t
  • 你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。

 

示例 1:

\"\"
输入:head = [1,2,3,4,5], k = 2
输出:
[2,1,4,3,5]

示例 2:

\"\"
输入:head = [1,2,3,4,5], k = 3
输出:
[3,2,1,4,5]

示例 3:

输入:head = [1,2,3,4,5], k = 1
输出:
[1,2,3,4,5]

示例 4:

输入:head = [1], k = 1
输出:
[1]

    提示:

      \t
    • 列表中节点的数量在范围 sz
    • \t
    • 1 <= sz <= 5000
    • \t
    • 0 <= Node.val <= 1000
    • \t
    • 1 <= k <= sz
    ", + "topic_link": "https://bbs.csdn.net/topics/600471012", + "cpp": "#include \nusing namespace std;\nstruct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode() : val(0), next(nullptr) {}\n\tListNode(int x) : val(x), next(nullptr) {}\n\tListNode(int x, ListNode *next) : val(x), next(next) {}\n};\nclass Solution\n{\npublic:\n\tListNode *reverseGroup(ListNode *head, int k)\n\t{\n\t\tint len = 0;\n\t\tstruct ListNode dummy, *prev = &dummy;\n\t\tdummy.next = head;\n\t\tfor (; head != nullptr; head = head->next)\n\t\t{\n\t\t\tif (++len % k == 0)\n\t\t\t{\n\t\t\t\tstruct ListNode *p = prev->next;\n\t\t\t\twhile (prev->next != head)\n\t\t\t\t{\n\t\t\t\t\tstruct ListNode *q = p->next;\n\t\t\t\t\tp->next = q->next;\n\t\t\t\t\tq->next = prev->next;\n\t\t\t\t\tprev->next = q;\n\t\t\t\t}\n\t\t\t\tprev = p;\n\t\t\t\thead = p;\n\t\t\t}\n\t\t}\n\t\treturn dummy.next;\n\t}\n};", + "java": "\npublic class ListNode {\n\tint val;\n\tListNode next;\n\n\tListNode() {\n\t}\n\n\tListNode(int val) {\n\t\tthis.val = val;\n\t}\n\n\tListNode(int val, ListNode next) {\n\t\tthis.val = val;\n\t\tthis.next = next;\n\t}\n}\n\nclass Solution {\n\tpublic ListNode reverseKGroup(ListNode head, int k) {\n\t\tif (head == null) {\n\t\t\treturn null;\n\t\t}\n\t\tListNode a = head, b = head;\n\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tif (b == null) {\n\t\t\t\treturn a;\n\t\t\t}\n\t\t\tb = b.next;\n\t\t}\n\n\t\tListNode newHead = reverse(a, b);\n\n\t\ta.next = reverseKGroup(b, k);\n\t\treturn newHead;\n\t}\n\n\tpublic ListNode reverse(ListNode a, ListNode b) {\n\t\tListNode pre, cur, nxt;\n\t\tpre = null;\n\t\tcur = a;\n\t\tnxt = a;\n\t\twhile (nxt != b) {\n\t\t\tnxt = cur.next;\n\t\t\tcur.next = pre;\n\t\t\tpre = cur;\n\t\t\tcur = nxt;\n\t\t}\n\t\treturn pre;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef reverseKGroup(self, head, k):\n\t\tif head is None:\n\t\t\treturn None\n\t\tindex = 0\n\t\tlead, last = 0, 0\n\t\tpos = head\n\t\ttemp = ListNode(-1)\n\t\ttemp.next = head\n\t\thead = temp\n\t\tstart = head\n\t\twhile pos is not None:\n\t\t\tif index % k == k - 1:\n\t\t\t\tlast = pos.next\n\t\t\t\tstart = self.reverseList(start, last)\n\t\t\t\tpos = start\n\t\t\tpos = pos.next\n\t\t\tindex += 1\n\t\treturn head.next\n\tdef reverseList(self, head, end):\n\t\tpos = head.next\n\t\tlast = end\n\t\tnext_start = pos\n\t\twhile pos != end:\n\t\t\thead.next = pos\n\t\t\tlast_pos = pos\n\t\t\tpos = pos.next\n\t\t\tlast_pos.next = last\n\t\t\tlast = last_pos\n\t\treturn next_start\n# %%\nl = LinkList()\nhead = [1,2,3,4, 5]\nl1 = l.initList(head)\ns = Solution()\nprint(l.convert_list(s.reverseKGroup(l1, k = 2)))", + "status": 1, + "keywords": "递归,链表", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/24/24_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/24/24_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/24/24_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/25.json b/data_backup/leetcode/25.json new file mode 100644 index 000000000..092cf5b65 --- /dev/null +++ b/data_backup/leetcode/25.json @@ -0,0 +1,24 @@ +{ + "question_id": 26, + "question_title": "删除有序数组中的重复项", + "difficulty": "简单", + "question_content": "
    \n

    给你一个有序数组 nums ,请你\n 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。

    \n\n

    不要使用额外的数组空间,你必须在 原地\n 修改输入数组 并在使用 O(1) 额外空间的条件下完成。

    \n\n

     

    \n\n

    说明:

    \n\n

    为什么返回数值是整数,但输出的答案是数组呢?

    \n\n

    请注意,输入数组是以「引用」方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。

    \n\n

    你可以想象内部操作如下:

    \n\n
    // nums 是以“引用”方式传递的。也就是说,不对实参做任何拷贝\nint len = removeDuplicates(nums);\n\n// 在函数里修改输入数组对于调用者是可见的。\n// 根据你的函数返回的长度, 它会打印出数组中 该长度范围内 的所有元素。\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}\n
    \n  \n\n

    示例 1:

    \n\n
    输入:nums = [1,1,2]\n
    输出:
    2, nums = [1,2]\n
    解释:
    函数应该返回新的长度 2 ,并且原数组 nums 的前两个元素被修改为 1, 2 。不需要考虑数组中超出新长度后面的元素。\n
    \n\n

    示例 2:

    \n\n
    输入:nums = [0,0,1,1,1,2,2,3,3,4]\n
    输出:
    5, nums = [0,1,2,3,4]\n
    解释:
    函数应该返回新的长度 5 , 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4 。不需要考虑数组中超出新长度后面的元素。\n
    \n\n

     

    \n\n

    提示:

    \n\n
      \n
    • 0 <= nums.length <= 3 * 104
    • \n
    • -104 <= nums[i] <= 104
    • \n
    • nums 已按升序排列
    • \n
    \n\n

     

    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470118", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint removeDuplicates(vector &nums)\n\t{\n\t\tif (nums.size() == 0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\tint count = 1;\n\t\tfor (int i = 1; i < nums.size(); i++)\n\t\t{\n\t\t\tif (nums[i - 1] != nums[i])\n\t\t\t{\n\t\t\t\tnums[count++] = nums[i];\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n};", + "java": "class Solution {\n\tpublic int removeDuplicates(int[] nums) {\n\t\tif (nums == null || nums.length == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tint a = 0;\n\t\tfor (int b = 1; b < nums.length; b++) {\n\t\t\tif (nums[a] != nums[b]) {\n\t\t\t\ta++;\n\t\t\t\tnums[a] = nums[b];\n\t\t\t}\n\t\t}\n\t\treturn a + 1;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef removeDuplicates(self, nums):\n\t\tif len(nums) == 0:\n\t\t\treturn 0\n\t\tleft = 0\n\t\tfor i in range(1, len(nums)):\n\t\t\tif nums[left] == nums[i]:\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tleft += 1\n\t\t\t\tnums[left] = nums[i]\n\t\treturn left + 1\n# %%\ns = Solution()\nprint(s.removeDuplicates(nums = [1,1,2]))", + "status": 1, + "keywords": "数组,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/25/25_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/25/25_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/25/25_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/26.json b/data_backup/leetcode/26.json new file mode 100644 index 000000000..e37b0c570 --- /dev/null +++ b/data_backup/leetcode/26.json @@ -0,0 +1,24 @@ +{ + "question_id": 27, + "question_title": "移除元素", + "difficulty": "简单", + "question_content": "
    \n

    给你一个数组 nums 和一个值 val,你需要 原地\n 移除所有数值等于 val 的元素,并返回移除后数组的新长度。

    \n\n

    不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组

    \n\n

    元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。

    \n\n

     

    \n\n

    说明:

    \n\n

    为什么返回数值是整数,但输出的答案是数组呢?

    \n\n

    请注意,输入数组是以「引用」方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。

    \n\n

    你可以想象内部操作如下:

    \n\n
    // nums 是以“引用”方式传递的。也就是说,不对实参作任何拷贝\nint len = removeElement(nums, val);\n\n// 在函数里修改输入数组对于调用者是可见的。\n// 根据你的函数返回的长度, 它会打印出数组中 该长度范围内 的所有元素。\nfor (int i = 0; i < len; i++) {\n    print(nums[i]);\n}\n
    \n\n

     

    \n\n

    示例 1:

    \n\n
    输入:nums = [3,2,2,3], val = 3\n
    输出:
    2, nums = [2,2]\n
    解释:
    函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。你不需要考虑数组中超出新长度后面的元素。例如,函数返回的新长度为 2 ,而 nums = [2,2,3,3] 或 nums = [2,2,0,0],也会被视作正确答案。\n
    \n\n

    示例 2:

    \n\n
    输入:nums = [0,1,2,2,3,0,4,2], val = 2\n
    输出:
    5, nums = [0,1,4,0,3]\n
    解释:
    函数应该返回新的长度 5, 并且 nums 中的前五个元素为 0, 1, 3, 0, 4。注意这五个元素可为任意顺序。你不需要考虑数组中超出新长度后面的元素。\n
    \n\n

     

    \n\n

    提示:

    \n\n
      \n
    • 0 <= nums.length <= 100
    • \n
    • 0 <= nums[i] <= 50
    • \n
    • 0 <= val <= 100
    • \n
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470219", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint removeElement(vector &nums, int val)\n\t{\n\t\tint count = 0;\n\t\tfor (int i = 0; i < nums.size(); i++)\n\t\t{\n\t\t\tif (nums[i] != val)\n\t\t\t{\n\t\t\t\tnums[count++] = nums[i];\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n};", + "java": "class Solution {\n\tpublic int removeElement(int[] nums, int val) {\n\n\t\tint len = nums.length;\n\t\tfor (int i = 0; i < len;) {\n\t\t\tif (nums[i] == val) {\n\t\t\t\tnums[i] = nums[len - 1];\n\t\t\t\tlen--;\n\t\t\t} else {\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t}\n\t\treturn len;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef removeElement(self, nums, val):\n\t\tls = len(nums)\n\t\tif ls == 0:\n\t\t\treturn ls\n\t\tcount = 0\n\t\tindex = 0\n\t\twhile index < ls - count:\n\t\t\tif nums[index] == val:\n\t\t\t\tnums[index] = nums[ls - 1 - count]\n\t\t\t\tcount += 1\n\t\t\telse:\n\t\t\t\tindex += 1\n\t\treturn ls - count\nif __name__ == '__main__':\n\ts = Solution()\n\tprint(s.removeElement([3,2,2,3], 3))", + "status": 1, + "keywords": "数组,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/26/26_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/26/26_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/26/26_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/27.json b/data_backup/leetcode/27.json new file mode 100644 index 000000000..696dd7b30 --- /dev/null +++ b/data_backup/leetcode/27.json @@ -0,0 +1,24 @@ +{ + "question_id": 28, + "question_title": "实现 strStr()", + "difficulty": "简单", + "question_content": "

    实现 strStr() 函数。

    \n

    给你两个字符串 haystackneedle ,请你在 haystack 字符串中找出 needle\n 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回  -1

    \n

     

    \n

    说明:

    \n

    当 needle 是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。

    \n

    对于本题而言,当 needle 是空字符串时我们应当返回 0 。这与 C 语言的 strstr() 以及 Java 的 indexOf() 定义相符。

    \n

     

    \n

    示例 1:

    \n
    输入:haystack = \"hello\", needle = \"ll\"
    输出:
    2
    \n

    示例 2:

    \n
    输入:haystack = \"aaaaa\", needle = \"bba\"
    输出:
    -1
    \n

    示例 3:

    \n
    输入:haystack = \"\", needle = \"\"
    输出:
    0
    \n

     

    \n

    提示:

    \n
      \n
    • 0 <= haystack.length, needle.length <= 5 * 104
    • \n
    • haystackneedle 仅由小写英文字符组成
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470119", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint strStr(string haystack, string needle)\n\t{\n\t\treturn haystack.find(needle);\n\t}\n};", + "java": "class Solution {\n\tpublic int strStr(String haystack, String needle) {\n\t\tif (needle.length() < 1) {\n\t\t\treturn 0;\n\t\t}\n\t\tchar[] ha = haystack.toCharArray();\n\t\tchar[] ne = needle.toCharArray();\n\t\tint hi = 0;\n\t\tint ni = 0;\n\t\tint[] next = getNextArray(ne);\n\t\twhile (hi < ha.length && ni < ne.length) {\n\t\t\tif (ha[hi] == ne[ni]) {\n\t\t\t\thi++;\n\t\t\t\tni++;\n\t\t\t} else {\n\t\t\t\tif (next[ni] == -1) {\n\t\t\t\t\thi++;\n\t\t\t\t} else {\n\t\t\t\t\tni = next[ni];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ni == ne.length ? hi - ni : -1;\n\t}\n\tpublic static int[] getNextArray(char[] a) {\n\t\tif (a.length == 1) {\n\t\t\treturn new int[] { -1 };\n\t\t}\n\t\tint[] next = new int[a.length];\n\t\tnext[0] = -1;\n\t\tnext[1] = 0;\n\t\tint i = 2;\n\t\tint j = 0;\n\t\twhile (i < next.length) {\n\t\t\tif (a[i - 1] == a[j]) {\n\t\t\t\tnext[i++] = ++j;\n\t\t\t} else if (j > 0) {\n\t\t\t\tj = next[j];\n\t\t\t} else {\n\t\t\t\tnext[i++] = 0;\n\t\t\t}\n\t\t}\n\t\treturn next;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef strStr(self, haystack, needle):\n\t\tlsh, lsn = len(haystack), len(needle)\n\t\tif lsn == 0:\n\t\t\treturn 0\n\t\tnext = self.makeNext(needle)\n\t\ti = j = 0\n\t\twhile i < lsh:\n\t\t\tif j == -1 or haystack[i] == needle[j]:\n\t\t\t\ti += 1\n\t\t\t\tj += 1\n\t\t\t\tif j == lsn:\n\t\t\t\t\treturn i - lsn\n\t\t\tif i < lsh and haystack[i] != needle[j]:\n\t\t\t\tj = next[j]\n\t\treturn -1\n\tdef makeNext(self, needle):\n\t\tls = len(needle)\n\t\tnext = [0] * ls\n\t\tnext[0], i, j = -1, 0, -1\n\t\twhile i < ls - 1:\n\t\t\tif j == -1 or needle[i] == needle[j]:\n\t\t\t\tnext[i + 1] = j + 1\n\t\t\t\tif needle[i + 1] == needle[j + 1]:\n\t\t\t\t\tnext[i + 1] = next[j + 1]\n\t\t\t\ti += 1\n\t\t\t\tj += 1\n\t\t\tif needle[i] != needle[j]:\n\t\t\t\tj = next[j]\n\t\treturn next\n# %%\ns = Solution()\nprint(s.strStr(haystack = \"hello\", needle = \"ll\"))", + "status": 0, + "keywords": "双指针,字符串,字符串匹配", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_43780574/article/details/84397763" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/27/27_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/27/27_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/27/27_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/28.json b/data_backup/leetcode/28.json new file mode 100644 index 000000000..99c03cd42 --- /dev/null +++ b/data_backup/leetcode/28.json @@ -0,0 +1,24 @@ +{ + "question_id": 29, + "question_title": "两数相除", + "difficulty": "中等", + "question_content": "

    给定两个整数,被除数 dividend 和除数 divisor。将两数相除,要求不使用乘法、除法和 mod 运算符。

    返回被除数 dividend 除以除数 divisor 得到的商。

    整数除法的结果应当截去(truncate)其小数部分,例如:truncate(8.345) = 8 以及 truncate(-2.7335) = -2

     

    示例 1:

    输入: dividend = 10, divisor = 3
    输出:
    3
    解释:
    10/3 = truncate(3.33333..) = truncate(3) = 3

    示例 2:

    输入: dividend = 7, divisor = -3
    输出:
    -2
    解释:
    7/-3 = truncate(-2.33333..) = -2

     

    提示:

      \t
    • 被除数和除数均为 32 位有符号整数。
    • \t
    • 除数不为 0。
    • \t
    • 假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231,  231 − 1]。本题中,如果除法结果溢出,则返回 231 − 1。
    ", + "topic_link": "https://bbs.csdn.net/topics/600470833", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint divide(int dividend, int divisor)\n\t{\n\t\tint signal = 1;\n\t\tunsigned int dvd = dividend;\n\t\tif (dividend < 0)\n\t\t{\n\t\t\tsignal *= -1;\n\t\t\tdvd = ~dvd + 1;\n\t\t}\n\t\tunsigned int dvs = divisor;\n\t\tif (divisor < 0)\n\t\t{\n\t\t\tsignal *= -1;\n\t\t\tdvs = ~dvs + 1;\n\t\t}\n\t\tint shift = 0;\n\t\twhile (dvd > dvs << shift)\n\t\t{\n\t\t\tshift++;\n\t\t}\n\t\tunsigned int res = 0;\n\t\twhile (dvd >= dvs)\n\t\t{\n\t\t\twhile (dvd < dvs << shift)\n\t\t\t{\n\t\t\t\tshift--;\n\t\t\t}\n\t\t\tres |= (unsigned int)1 << shift;\n\t\t\tdvd -= dvs << shift;\n\t\t}\n\t\tif (signal == 1 && res >= INT_MAX)\n\t\t{\n\t\t\treturn INT_MAX;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn res * signal;\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic int divide(int dividend, int divisor) {\n\t\tif (dividend == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dividend == Integer.MIN_VALUE && divisor == -1) {\n\t\t\treturn Integer.MAX_VALUE;\n\t\t}\n\t\tboolean negative;\n\t\tnegative = (dividend ^ divisor) < 0;\n\t\tlong t = Math.abs((long) dividend);\n\t\tlong d = Math.abs((long) divisor);\n\t\tint result = 0;\n\t\tfor (int i = 31; i >= 0; i--) {\n\t\t\tif ((t >> i) >= d) {\n\t\t\t\tresult += 1 << i;\n\t\t\t\tt -= d << i;\n\t\t\t}\n\t\t}\n\t\treturn negative ? -result : result;\n\t}\n}", + "js": "", + "python": "import math\nclass Solution(object):\n\tdef divide(self, dividend, divisor):\n\t\tif divisor == 0:\n\t\t\treturn MAX_INT\n\t\tif dividend == 0:\n\t\t\treturn 0\n\t\tisPositive = (dividend < 0) == (divisor < 0)\n\t\tm = abs(dividend)\n\t\tn = abs(divisor)\n\t\tres = math.log(m) - math.log(n)\n\t\tres = int(math.exp(res))\n\t\tif isPositive:\n\t\t\treturn min(res, 2147483647)\n\t\treturn max(0 - res, -2147483648)\nif __name__ == '__main__':\n\ts = Solution()\n\tprint(s.divide(1, 1))", + "status": 1, + "keywords": "位运算,数学", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104292233" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/28/28_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/28/28_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/28/28_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/29.json b/data_backup/leetcode/29.json new file mode 100644 index 000000000..dc02bbd04 --- /dev/null +++ b/data_backup/leetcode/29.json @@ -0,0 +1,24 @@ +{ + "question_id": 30, + "question_title": "串联所有单词的子串", + "difficulty": "困难", + "question_content": "

    给定一个字符串 和一些长度相同的单词 words。找出 s\n 中恰好可以由 words 中所有单词串联形成的子串的起始位置。

    \n

    注意子串要与 words 中的单词完全匹配,中间不能有其他字符,但不需要考虑 words 中单词串联的顺序。

    \n

     

    \n

    示例 1:

    \n
    输入:  s = "barfoothefoobarman",  words = ["foo","bar"]
    输出:
    [0,9]
    解释:
    从索引 0 和 9 开始的子串分别是 "barfoo" 和 "foobar" 。输出的顺序不重要, [9,0] 也是有效答案。
    \n

    示例 2:

    \n
    输入:  s = "wordgoodgoodgoodbestword",  words = ["word","good","best","word"]
    输出:
    []
    ", + "topic_link": "https://bbs.csdn.net/topics/600470925", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector findSubstring(string s, vector &words)\n\t{\n\t\tvector res;\n\t\tif (s.empty() || words.empty())\n\t\t{\n\t\t\treturn res;\n\t\t}\n\t\tunordered_map ht;\n\t\tfor (const auto &w : words)\n\t\t{\n\t\t\tht[w]++;\n\t\t}\n\t\tint len = words[0].length();\n\t\tfor (int i = 0, j = 0; i < s.length() - words.size() * len + 1; i++)\n\t\t{\n\t\t\tunordered_map counting;\n\t\t\tfor (j = 0; j < words.size(); j++)\n\t\t\t{\n\t\t\t\tstring word = s.substr(i + j * len, len);\n\t\t\t\tif (++counting[word] > ht[word])\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (j == words.size())\n\t\t\t{\n\t\t\t\tres.push_back(i);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n};", + "java": "class Solution {\n\tpublic List findSubstring(String s, String[] words) {\n\t\tList res = new ArrayList<>();\n\t\tif (s == null || s.length() == 0 || words == null || words.length == 0)\n\t\t\treturn res;\n\t\tHashMap map = new HashMap<>();\n\t\tint one_word = words[0].length();\n\t\tint word_num = words.length;\n\t\tint all_len = one_word * word_num;\n\t\tfor (String word : words) {\n\t\t\tmap.put(word, map.getOrDefault(word, 0) + 1);\n\t\t}\n\t\tfor (int i = 0; i < one_word; i++) {\n\t\t\tint left = i, right = i, count = 0;\n\t\t\tHashMap tmp_map = new HashMap<>();\n\t\t\twhile (right + one_word <= s.length()) {\n\t\t\t\tString w = s.substring(right, right + one_word);\n\t\t\t\tright += one_word;\n\t\t\t\tif (!map.containsKey(w)) {\n\t\t\t\t\tcount = 0;\n\t\t\t\t\tleft = right;\n\t\t\t\t\ttmp_map.clear();\n\t\t\t\t} else {\n\t\t\t\t\ttmp_map.put(w, tmp_map.getOrDefault(w, 0) + 1);\n\t\t\t\t\tcount++;\n\t\t\t\t\twhile (tmp_map.getOrDefault(w, 0) > map.getOrDefault(w, 0)) {\n\t\t\t\t\t\tString t_w = s.substring(left, left + one_word);\n\t\t\t\t\t\tcount--;\n\t\t\t\t\t\ttmp_map.put(t_w, tmp_map.getOrDefault(t_w, 0) - 1);\n\t\t\t\t\t\tleft += one_word;\n\t\t\t\t\t}\n\t\t\t\t\tif (count == word_num)\n\t\t\t\t\t\tres.add(left);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef findSubstring(self, s, words):\n\t\t\"\"\"\n\t\t:type s: str\n\t\t:type words: List[str]\n\t\t:rtype: List[int]\n\t\t\"\"\"\n\t\tls = len(s)\n\t\tword_ls = len(words[0])\n\t\ttarget_dict = {}\n\t\tfor word in words:\n\t\t\ttry:\n\t\t\t\ttarget_dict[word] += 1\n\t\t\texcept KeyError:\n\t\t\t\ttarget_dict[word] = 1\n\t\tres = []\n\t\tfor start in range(ls - word_ls * len(words) + 1):\n\t\t\tcurr_dict = target_dict.copy()\n\t\t\tfor pos in range(start, start + word_ls * len(words), word_ls):\n\t\t\t\tcurr = s[pos:pos + word_ls]\n\t\t\t\ttry:\n\t\t\t\t\tcurr_dict[curr] -= 1\n\t\t\t\t\tif curr_dict[curr] < 0:\n\t\t\t\t\t\tbreak\n\t\t\t\texcept KeyError:\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tres.append(start)\n\t\treturn res\nif __name__ == '__main__':\n\ts = Solution()\n\tprint(s.findSubstring('wordgoodgoodgoodbestword', [\"word\", \"good\", \"best\", \"good\"]))", + "status": 1, + "keywords": "哈希表,字符串,滑动窗口", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104292954" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/29/29_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/29/29_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/29/29_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/3.json b/data_backup/leetcode/3.json new file mode 100644 index 000000000..09df958a6 --- /dev/null +++ b/data_backup/leetcode/3.json @@ -0,0 +1,24 @@ +{ + "question_id": 4, + "question_title": "寻找两个正序数组的中位数", + "difficulty": "困难", + "question_content": "

    给定两个大小分别为 mn 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数

     

    示例 1:

    输入:nums1 = [1,3], nums2 = [2]
    输出:
    2.00000
    解释:
    合并数组 = [1,2,3] ,中位数 2

    示例 2:

    输入:nums1 = [1,2], nums2 = [3,4]
    输出:
    2.50000
    解释:
    合并数组 = [1,2,3,4] ,中位数 (2 + 3) / 2 = 2.5

    示例 3:

    输入:nums1 = [0,0], nums2 = [0,0]
    输出:
    0.00000

    示例 4:

    输入:nums1 = [], nums2 = [1]
    输出:
    1.00000

    示例 5:

    输入:nums1 = [2], nums2 = []
    输出:
    2.00000

     

    提示:

      \t
    • nums1.length == m
    • \t
    • nums2.length == n
    • \t
    • 0 <= m <= 1000
    • \t
    • 0 <= n <= 1000
    • \t
    • 1 <= m + n <= 2000
    • \t
    • -106 <= nums1[i], nums2[i] <= 106

     

    进阶:你能设计一个时间复杂度为 O(log (m+n)) 的算法解决此问题吗?

    ", + "topic_link": "https://bbs.csdn.net/topics/600469814", + "cpp": "class Solution\n{\npublic:\n\tdouble findMedianSortedArrays(vector &nums1, vector &nums2)\n\t{\n\t\tint nums1Size = nums1.size();\n\t\tint nums2Size = nums2.size();\n\t\tint na = nums1Size + nums2Size;\n\t\tint *ns = (int *)malloc(4 * na);\n\t\tint i = 0, j = 0, d = 0;\n\t\tint m = na / 2 + 1;\n\t\twhile (d < m)\n\t\t{\n\t\t\tint n;\n\t\t\tif (i < nums1Size && j < nums2Size)\n\t\t\t{\n\t\t\t\tn = (nums1[i] < nums2[j]) ? nums1[i++] : nums2[j++];\n\t\t\t}\n\t\t\telse if (i < nums1Size)\n\t\t\t{\n\t\t\t\tn = nums1[i++];\n\t\t\t}\n\t\t\telse if (j < nums2Size)\n\t\t\t{\n\t\t\t\tn = nums2[j++];\n\t\t\t}\n\t\t\tns[d++] = n;\n\t\t}\n\t\tif (na % 2)\n\t\t{\n\t\t\treturn ns[d - 1];\n\t\t}\n\t\treturn (ns[d - 1] + ns[d - 2]) / 2.0;\n\t}\n};", + "java": "class Solution {\n\tpublic double findMedianSortedArrays(int[] nums1, int[] nums2) {\n\t\tint nums1Size = nums1.length;\n\t\tint nums2Size = nums2.length;\n\t\tint na = nums1Size + nums2Size;\n\t\tint[] ns = new int[4 * na];\n\t\tint i = 0, j = 0, d = 0;\n\t\tint m = na / 2 + 1;\n\t\twhile (d < m) {\n\t\t\tint n = 0;\n\t\t\tif (i < nums1Size && j < nums2Size) {\n\t\t\t\tn = (nums1[i] < nums2[j]) ? nums1[i++] : nums2[j++];\n\t\t\t} else if (i < nums1Size) {\n\t\t\t\tn = nums1[i++];\n\t\t\t} else if (j < nums2Size) {\n\t\t\t\tn = nums2[j++];\n\t\t\t}\n\t\t\tns[d++] = n;\n\t\t}\n\t\tif (na % 2 == 1) {\n\t\t\treturn ns[d - 1];\n\t\t}\n\t\treturn (ns[d - 1] + ns[d - 2]) / 2.0;\n\t}\n}", + "js": "/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar findMedianSortedArrays = function(nums1, nums2) {\n let A, B, m, n, l, start, end, cutA, cutBB, cutB, L1, R1, L2, R2, U;\n \n if(nums2.length case:', A, B);\n \n [m, n] = [A.length, B.length];\n l = m+n;\n\n if(m===0||n===0){\n if(m!==0){\n U = A;\n }\n\n if(n!==0){\n U = B;\n }\n\n if(U==null){\n return 0;\n }\n\n if(l%2===0){\n return (U[l/2-1]+U[l/2])/2;\n }else{\n return U[(l-1)/2];\n }\n\n }\n\n start = 0;\n end = m;\n while(start<=end){\n cutA = Math.floor((start+end)/2);\n cutBB = Math.floor((l+1)/2);\n cutB = cutBB-cutA;\n\n L1 = cutA===0 ? Number.NEGATIVE_INFINITY : A[cutA-1];\n R1 = cutA===m ? Number.MAX_VALUE : A[cutA];\n\n L2 = cutB===0 ? Number.NEGATIVE_INFINITY : B[cutB-1];\n R2 = cutB===n ? Number.MAX_VALUE : B[cutB];\n\n console.log(`-->[${start}, ${end}], [${cutA},${cutB}, ${cutBB}], L1:${L1}, R1:${R1}, L2:${L2}, R2:${R2}`);\n\n if(cutA>0 && L1>R2){\n end--;\n }else if(L2>R1){\n start++;\n }else{\n if(l%2===0){\n return (Math.max(L1,L2)+Math.min(R1,R2))/2;\n }else{\n return Math.max(L1, L2);\n }\n }\n }\n\n return 0;\n};\n\n\nconst cases = [\n // 0, 0\n [[],[],0],\n\n // 0, x\n [[],[2,4],3],\n [[],[2,4,5],4],\n [[1],[2,3],2],\n\n // // x, 0\n [[2,4],[],3],\n\n // // 1,1\n [[2],[3],2.5],\n \n // 2,1\n [[1,3],[2],2],\n\n // 1,2\n [[2],[1,3],2],\n [[4],[2,2],2], // 2,2,4=>2\n [[4],[2,4],4], // 2,4,4=>4\n [[4],[2,3],3],\n [[1],[2,3,4],2.5],\n [[1],[2,3,4,5,6],3.5],\n\n // 2,2\n [[1,2],[3,4],2.5],\n [[1,4],[2,3],2.5],\n [[2,3],[1,4],2.5],\n\n // 3,2\n [[2,3,4],[1,4],3], // 1,2,3,4,4\n [[1,2,3],[1,2],2], // 1,1,2,2,3\n [[1,2],[1,2,3],2], // 1,1,2,2,3\n\n // 3,3\n [[1,1,1],[1,1,1],1],\n [[1,2,2],[1,2,3],2],\n [[1,2,2, 2],[1,2, 2, 2],2], // 1 1 2 2 2\n\n // 4, 2\n [[2,3,4,5],[1,4],3.5], // 1,2,3,4,4,5\n [ [1,2,3,7,8],\n [4,5,6,9,10],\n 5.5\n ]\n];\n\nfor(const c of cases){\n console.log('');\n const v = findMedianSortedArrays(c[0], c[1]);\n console.log('v:',v);\n console.assert(v===c[2]); \n}\n\n\n\n\n\n\n\n", + "python": "import math\nfrom typing import List\nclass Solution:\n\tdef findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:\n\t\tnums1Size = len(nums1)\n\t\tnums2Size = len(nums2)\n\t\tna = nums1Size + nums2Size\n\t\tns = []\n\t\ti = 0\n\t\tj = 0\n\t\tm = int(math.floor(na / 2 + 1))\n\t\twhile len(ns) < m:\n\t\t\tn = None\n\t\t\tif i < nums1Size and j < nums2Size:\n\t\t\t\tif nums1[i] < nums2[j]:\n\t\t\t\t\tn = nums1[i]\n\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\tn = nums2[j]\n\t\t\t\t\tj += 1\n\t\t\telif i < nums1Size:\n\t\t\t\tn = nums1[i]\n\t\t\t\ti += 1\n\t\t\telif j < nums2Size:\n\t\t\t\tn = nums2[j]\n\t\t\t\tj += 1\n\t\t\tns.append(n)\n\t\td = len(ns)\n\t\tif na % 2 == 1:\n\t\t\treturn ns[d - 1]\n\t\telse:\n\t\t\treturn (ns[d - 1] + ns[d - 2]) / 2.0\n# %%\ns = Solution()\nprint(s.findMedianSortedArrays([1,3], [2]))", + "status": 1, + "keywords": "数组,二分查找,分治", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/3/3_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/3/3_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/3/3_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/30.json b/data_backup/leetcode/30.json new file mode 100644 index 000000000..487c91475 --- /dev/null +++ b/data_backup/leetcode/30.json @@ -0,0 +1,24 @@ +{ + "question_id": 31, + "question_title": "下一个排列", + "difficulty": "中等", + "question_content": "

    实现获取 下一个排列 的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列。

    如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列)。

    必须 原地 修改,只允许使用额外常数空间。

     

    示例 1:

    输入:nums = [1,2,3]
    输出:
    [1,3,2]

    示例 2:

    输入:nums = [3,2,1]
    输出:
    [1,2,3]

    示例 3:

    输入:nums = [1,1,5]
    输出:
    [1,5,1]

    示例 4:

    输入:nums = [1]
    输出:
    [1]

     

    提示:

      \t
    • 1 <= nums.length <= 100
    • \t
    • 0 <= nums[i] <= 100
    ", + "topic_link": "https://bbs.csdn.net/topics/600471007", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvoid nextPermutation(vector &nums)\n\t{\n\t\tif (nums.size() < 2)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tint i = nums.size() - 2;\n\t\twhile (i >= 0 && nums[i] >= nums[i + 1])\n\t\t{\n\t\t\ti--;\n\t\t}\n\t\tif (i >= 0)\n\t\t{\n\t\t\tint j = nums.size() - 1;\n\t\t\twhile (j >= 0 && nums[j] >= nums[i])\n\t\t\t{\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tswap(nums.begin() + i, nums.begin() + j);\n\t\t}\n\t\treverse(nums.begin() + i + 1, nums.end());\n\t}\n};", + "java": "class Solution {\n\tpublic void nextPermutation(int[] nums) {\n\t\tint i = nums.length - 1;\n\t\twhile (i > 0 && nums[i] <= nums[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i > 0) {\n\t\t\tint j = nums.length - 1;\n\t\t\twhile (j >= 0 && nums[j] <= nums[i - 1]) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tswap(nums, i - 1, j);\n\t\t}\n\t\treverse(nums, i);\n\t}\n\tprivate void reverse(int[] nums, int i) {\n\t\tint j = nums.length - 1;\n\t\twhile (i < j) {\n\t\t\tswap(nums, i, j);\n\t\t\ti++;\n\t\t\tj--;\n\t\t}\n\t}\n\tprivate void swap(int[] nums, int i, int j) {\n\t\tint temp = nums[i];\n\t\tnums[i] = nums[j];\n\t\tnums[j] = temp;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef nextPermutation(self, nums):\n\t\tls = len(nums)\n\t\tif ls <= 1:\n\t\t\treturn\n\t\tpair = []\n\t\tfor i in range(ls):\n\t\t\tfor j in range(i + 1, ls):\n\t\t\t\tif nums[i] < nums[j]:\n\t\t\t\t\tpair.append([i,j])\n\t\tpos = 0\n\t\tif len(pair) > 0:\n\t\t\tself.swap(nums, pair[-1][0], pair[-1][1])\n\t\t\tpos = pair[-1][0] + 1\n\t\tfor i in range(pos, ls):\n\t\t\tfor j in range(i + 1, ls):\n\t\t\t\tif nums[i] > nums[j]:\n\t\t\t\t\tself.swap(nums, i, j)\n\t\treturn nums\n\tdef swap(self, nums, index1, index2):\n\t\tif index1 == index2:\n\t\t\treturn\n\t\tnums[index1], nums[index2] = nums[index2], nums[index1]\n# %%\ns = Solution()\nprint(s.nextPermutation(nums = [1,2,3]))", + "status": 1, + "keywords": "数组,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/qq_41645636/article/details/98349631" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/30/30_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/30/30_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/30/30_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/31.json b/data_backup/leetcode/31.json new file mode 100644 index 000000000..529b8a2c4 --- /dev/null +++ b/data_backup/leetcode/31.json @@ -0,0 +1,24 @@ +{ + "question_id": 32, + "question_title": "最长有效括号", + "difficulty": "困难", + "question_content": "

    给你一个只包含 '(' 和 ')' 的字符串,找出最长有效(格式正确且连续)括号子串的长度。

     

    示例 1:

    输入:s = \"(()\"
    输出:
    2
    解释:
    最长有效括号子串是 \"()\"

    示例 2:

    输入:s = \")()())\"
    输出:
    4
    解释:
    最长有效括号子串是 \"()()\"

    示例 3:

    输入:s = \"\"
    输出:
    0

     

    提示:

      \t
    • 0 <= s.length <= 3 * 104
    • \t
    • s[i]'('')'
    ", + "topic_link": "https://bbs.csdn.net/topics/600471008", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint longestValidParentheses(string s)\n\t{\n\t\tstack stk;\n\t\tint invalid = -1;\n\t\tint len = 0, max_len = 0;\n\t\tfor (int i = 0; i < s.length(); i++)\n\t\t{\n\t\t\tif (s[i] == '(')\n\t\t\t{\n\t\t\t\tstk.push(i);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (stk.empty())\n\t\t\t\t{\n\t\t\t\t\tinvalid = i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tstk.pop();\n\t\t\t\t\tif (stk.empty())\n\t\t\t\t\t{\n\t\t\t\t\t\tmax_len = max(i - invalid, max_len);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmax_len = max(i - stk.top(), max_len);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn max_len;\n\t}\n};", + "java": "import java.util.*;\n\nclass Solution {\n\tpublic int longestValidParentheses(String s) {\n\t\tint left = 0, right = 0, max = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) == '(')\n\t\t\t\tleft++;\n\t\t\telse\n\t\t\t\tright++;\n\t\t\tif (left == right)\n\t\t\t\tmax = Math.max(max, left * 2);\n\t\t\tif (right > left)\n\t\t\t\tleft = right = 0;\n\t\t}\n\t\tleft = 0;\n\t\tright = 0;\n\t\tfor (int i = s.length() - 1; i >= 0; i--) {\n\t\t\tif (s.charAt(i) == '(')\n\t\t\t\tleft++;\n\t\t\telse\n\t\t\t\tright++;\n\t\t\tif (left == right)\n\t\t\t\tmax = Math.max(max, left * 2);\n\t\t\tif (right < left)\n\t\t\t\tleft = right = 0;\n\t\t}\n\t\treturn max;\n\t}\n}\n", + "js": "", + "python": "import pdb\nclass Solution(object):\n\tdef longestValidParentheses(self, s):\n\t\tls = len(s)\n\t\tstack = []\n\t\tdata = [0] * ls\n\t\tfor i in range(ls):\n\t\t\tcurr = s[i]\n\t\t\tif curr == '(':\n\t\t\t\tstack.append(i)\n\t\t\telse:\n\t\t\t\tif len(stack) > 0:\n\t\t\t\t\tdata[i] = 1\n\t\t\t\t\tdata[stack.pop(-1)] = 1\n\t\ttep, res = 0, 0\n\t\tfor t in data:\n\t\t\tif t == 1:\n\t\t\t\ttep += 1\n\t\t\telse:\n\t\t\t\tres = max(tep, res)\n\t\t\t\ttep = 0\n\t\treturn max(tep, res)\nif __name__ == '__main__':\n\ts = Solution()\n\tprint(s.longestValidParentheses(')()())'))", + "status": 1, + "keywords": "栈,字符串,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/31/31_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/31/31_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/31/31_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/32.json b/data_backup/leetcode/32.json new file mode 100644 index 000000000..d25ae2f6b --- /dev/null +++ b/data_backup/leetcode/32.json @@ -0,0 +1,24 @@ +{ + "question_id": 33, + "question_title": "搜索旋转排序数组", + "difficulty": "中等", + "question_content": "

    整数数组 nums 按升序排列,数组中的值 互不相同

    \n

    在传递给函数之前,nums 在预先未知的某个下标 k0 <= k < nums.length)上进行了 旋转,使数组变为\n [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]](下标 从 0 开始\n 计数)。例如, [0,1,2,4,5,6,7] 在下标 3 处经旋转后可能变为 [4,5,6,7,0,1,2] 。\n

    \n

    给你 旋转后 的数组 nums 和一个整数 target ,如果 nums 中存在这个目标值\n target ,则返回它的下标,否则返回 -1 。\n

    \n

     

    \n

    示例 1:

    \n
    输入:nums = [4,5,6,7,0,1,2], target = 0
    输出:
    4
    \n

    示例 2:

    \n
    输入:nums = [4,5,6,7,0,1,2], target = 3
    输出:
    -1
    \n

    示例 3:

    \n
    输入:nums = [1], target = 0
    输出:
    -1
    \n

     

    \n

    提示:

    \n
      \n
    • 1 <= nums.length <= 5000
    • \n
    • -10^4 <= nums[i] <= 10^4
    • \n
    • nums 中的每个值都 独一无二
    • \n
    • 题目数据保证 nums 在预先未知的某个下标上进行了旋转
    • \n
    • -10^4 <= target <= 10^4
    • \n
    \n

     

    \n

    进阶:你可以设计一个时间复杂度为 O(log n) 的解决方案吗?

    ", + "topic_link": "https://bbs.csdn.net/topics/600470220", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint search(vector &nums, int target)\n\t{\n\t\tint lo = 0;\n\t\tint hi = nums.size() - 1;\n\t\tfor (lo <= hi)\n\t\t{\n\t\t\tint mid = lo + (hi - lo) / 2;\n\t\t\tif (nums[mid] == target)\n\t\t\t{\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t\tif (nums[lo] <= nums[mid])\n\t\t\t{\n\t\t\t\tif (nums[lo] <= target && target < nums[mid])\n\t\t\t\t{\n\t\t\t\t\thi = mid - 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (nums[mid] < target && target <= nums[hi])\n\t\t\t\t{\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\thi = mid - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n};", + "java": "class Solution {\n\tpublic int search(int[] nums, int target) {\n\t\tint start = 0;\n\t\tint end = nums.length - 1;\n\n\t\twhile (start <= end) {\n\t\t\tint mid = start + (end - start) / 2;\n\t\t\tif (nums[mid] == target) {\n\t\t\t\treturn mid;\n\t\t\t}\n\n\t\t\tif (nums[start] <= nums[mid]) {\n\t\t\t\tif (target >= nums[start] && target <= nums[mid]) {\n\t\t\t\t\tend = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tstart = start + 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (nums[mid] <= nums[end]) {\n\t\t\t\tif (target >= nums[mid] && target <= nums[end]) {\n\t\t\t\t\tstart = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\tend = end - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n}\n", + "js": "", + "python": "class Solution:\n\tdef search(self, nums, target):\n\t\tdef get(start, end):\n\t\t\tif start > end:\n\t\t\t\treturn -1\n\t\t\tmid = (start + end) / 2\n\t\t\tmid = int(mid)\n\t\t\tif nums[mid] == target:\n\t\t\t\treturn mid\n\t\t\telif nums[mid] >= nums[start]: \n\t\t\t\tif target >= nums[start] and target < nums[mid]:\n\t\t\t\t\treturn get(start, mid - 1)\n\t\t\t\telse:\n\t\t\t\t\treturn get(mid + 1, end)\n\t\t\telif nums[mid] <= nums[end]: \n\t\t\t\tif target > nums[mid] and target <= nums[end]:\n\t\t\t\t\treturn get(mid + 1, end)\n\t\t\t\telse:\n\t\t\t\t\treturn get(start, mid - 1)\n\t\treturn get(0, len(nums) - 1)\n# %%\ns = Solution()\nprint(s.search(nums = [4,5,6,7,0,1,2], target = 0))", + "status": 1, + "keywords": "数组,二分查找", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/32/32_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/32/32_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/32/32_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/33.json b/data_backup/leetcode/33.json new file mode 100644 index 000000000..88575fd4c --- /dev/null +++ b/data_backup/leetcode/33.json @@ -0,0 +1,24 @@ +{ + "question_id": 34, + "question_title": "在排序数组中查找元素的第一个和最后一个位置", + "difficulty": "中等", + "question_content": "

    给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。

    \n

    如果数组中不存在目标值 target,返回 [-1, -1]

    \n

    进阶:

    \n
      \n
    • 你可以设计并实现时间复杂度为 O(log n) 的算法解决此问题吗?
    • \n
    \n

     

    \n

    示例 1:

    \n
    输入:nums = [5,7,7,8,8,10], target = 8
    输出:
    [3,4]
    \n

    示例 2:

    \n
    输入:nums = [5,7,7,8,8,10], target = 6
    输出:
    [-1,-1]
    \n

    示例 3:

    \n
    输入:nums = [], target = 0
    输出:
    [-1,-1]
    \n

     

    \n

    提示:

    \n
      \n
    • 0 <= nums.length <= 105
    • \n
    • -109 <= nums[i] <= 109
    • \n
    • nums 是一个非递减数组
    • \n
    • -109 <= target <= 109
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470221", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector searchRange(vector &nums, int target)\n\t{\n\t\tvector res;\n\t\tres.push_back(binary_search_begin(nums, target));\n\t\tres.push_back(binary_search_end(nums, target));\n\t\treturn res;\n\t}\nprivate:\n\tint binary_search_begin(vector nums, int target)\n\t{\n\t\tint lo = -1;\n\t\tint hi = nums.size();\n\t\twhile (lo + 1 < hi)\n\t\t{\n\t\t\tint mid = lo + (hi - lo) / 2;\n\t\t\tif (target > nums[mid])\n\t\t\t{\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t}\n\t\tif (hi == nums.size() || nums[hi] != target)\n\t\t{\n\t\t\treturn -1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn hi;\n\t\t}\n\t}\n\tint binary_search_end(vector nums, int target)\n\t{\n\t\tint lo = -1;\n\t\tint hi = nums.size();\n\t\twhile (lo + 1 < hi)\n\t\t{\n\t\t\tint mid = lo + (hi - lo) / 2;\n\t\t\tif (target < nums[mid])\n\t\t\t{\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t}\n\t\tif (lo == -1 || nums[lo] != target)\n\t\t{\n\t\t\treturn -1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn lo;\n\t\t}\n\t}\n};", + "java": "public class Solution {\n\n\tpublic int[] searchRange(int[] nums, int target) {\n\t\tint[] result = new int[2];\n\t\tresult[0] = floor(nums, target);\n\t\tresult[1] = ceil(nums, target);\n\t\treturn result;\n\t}\n\n\tprivate int floor(int[] nums, int target) {\n\t\tint left = -1;\n\t\tint right = nums.length - 1;\n\t\twhile (left < right) {\n\t\t\tint mid = left + (right - left + 1) / 2;\n\t\t\tif (target <= nums[mid]) {\n\t\t\t\tright = mid - 1;\n\t\t\t} else {\n\t\t\t\tleft = mid;\n\t\t\t}\n\t\t}\n\t\tif (left + 1 < nums.length && nums[left + 1] == target) {\n\t\t\treturn left + 1;\n\t\t} else {\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tprivate int ceil(int[] nums, int target) {\n\t\tint left = 0;\n\t\tint right = nums.length;\n\t\twhile (left < right) {\n\t\t\tint mid = left + (right - left) / 2;\n\t\t\tif (target >= nums[mid]) {\n\t\t\t\tleft = mid + 1;\n\t\t\t} else {\n\t\t\t\tright = mid;\n\t\t\t}\n\t\t}\n\t\tif (right - 1 >= 0 && nums[right - 1] == target) {\n\t\t\treturn right - 1;\n\t\t} else {\n\t\t\treturn -1;\n\t\t}\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef searchRange(self, nums, target):\n\t\tlength = len(nums)\n\t\tif length == 0:\n\t\t\treturn [-1, -1]\n\t\tmin = 0\n\t\tmax = length - 1\n\t\twhile min <= max:\n\t\t\tpos = (min + max) / 2\n\t\t\tpos = int(pos)\n\t\t\tif nums[pos] > target:\n\t\t\t\tmax = pos - 1\n\t\t\telif nums[pos] < target:\n\t\t\t\tmin = pos + 1\n\t\t\telse:\n\t\t\t\tfor i in range(min, max + 1):\n\t\t\t\t\tif nums[i] == target:\n\t\t\t\t\t\tif min < i and nums[min] != nums[i]:\n\t\t\t\t\t\t\tmin = i\n\t\t\t\t\t\tmax = i\n\t\t\t\treturn [min, max]\n\t\treturn [-1, -1]\n# %%\ns = Solution()\nprint(s.searchRange(nums = [5,7,7,8,8,10], target = 8))", + "status": 1, + "keywords": "数组,二分查找", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/33/33_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/33/33_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/33/33_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/34.json b/data_backup/leetcode/34.json new file mode 100644 index 000000000..b2b7e4bf8 --- /dev/null +++ b/data_backup/leetcode/34.json @@ -0,0 +1,24 @@ +{ + "question_id": 35, + "question_title": "搜索插入位置", + "difficulty": "简单", + "question_content": "

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。

    你可以假设数组中无重复元素。

    示例 1:

    输入: [1,3,5,6], 5
    输出:
    2

    示例 2:

    输入: [1,3,5,6], 2
    输出:
    1

    示例 3:

    输入: [1,3,5,6], 7
    输出:
    4

    示例 4:

    输入: [1,3,5,6], 0
    输出:
    0
    ", + "topic_link": "https://bbs.csdn.net/topics/600470222", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint searchInsert(vector &nums, int target)\n\t{\n\t\tint lo = -1;\n\t\tint hi = nums.size();\n\t\twhile (lo + 1 < hi)\n\t\t{\n\t\t\tint mid = lo + (hi - lo) / 2;\n\t\t\tif (target > nums[mid])\n\t\t\t{\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t}\n\t\treturn hi;\n\t}\n};", + "java": "class Solution {\n\tpublic int searchInsert(int[] nums, int target) {\n\t\tint left = 0, right = nums.length - 1;\n\t\tif (target < nums[left])\n\t\t\treturn 0;\n\t\tif (target > nums[right])\n\t\t\treturn nums.length;\n\t\twhile (left <= right) {\n\t\t\tint mid = (right - left) / 2 + left;\n\t\t\tif (target < nums[mid]) {\n\t\t\t\tright = mid - 1;\n\t\t\t} else if (target > nums[mid]) {\n\t\t\t\tleft = mid + 1;\n\t\t\t} else {\n\t\t\t\treturn mid;\n\t\t\t}\n\t\t}\n\t\treturn left;\n\t}\n}\n", + "js": "", + "python": "class Solution:\n\tdef searchInsert(self, nums, target):\n\t\tl, r = int(0), len(nums) - 1\n\t\twhile l < r:\n\t\t\tmid = int((l + r) / 2)\n\t\t\tif nums[mid] < target:\n\t\t\t\tl = mid + 1\n\t\t\telse:\n\t\t\t\tr = mid\n\t\tif nums[l] < target:\n\t\t\treturn l + 1\n\t\treturn l \nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.searchInsert([1,3,5,6],5))\t", + "status": 1, + "keywords": "数组,二分查找", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/34/34_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/34/34_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/34/34_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/35.json b/data_backup/leetcode/35.json new file mode 100644 index 000000000..7e17fb63c --- /dev/null +++ b/data_backup/leetcode/35.json @@ -0,0 +1,24 @@ +{ + "question_id": 36, + "question_title": "有效的数独", + "difficulty": "中等", + "question_content": "

    请你判断一个 9x9 的数独是否有效。只需要 根据以下规则 ,验证已经填入的数字是否有效即可。

    \n
      \n
    1. 数字 1-9 在每一行只能出现一次。
    2. \n
    3. 数字 1-9 在每一列只能出现一次。
    4. \n
    5. 数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。(请参考示例图)
    6. \n
    \n

    数独部分空格内已填入了数字,空白格用 '.' 表示。

    \n

    注意:

    \n
      \n
    • 一个有效的数独(部分已被填充)不一定是可解的。
    • \n
    • 只需要根据以上规则,验证已经填入的数字是否有效即可。
    • \n
    \n

     

    \n

    示例 1:

    \n
    输入:board = \n    [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n    ,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n    ,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n    ,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n    ,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n    ,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n    ,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n    ,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n    ,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n输出:true\n
    \n

    示例 2:

    \n
    输入:board = \n    [[\"8\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n    ,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n    ,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n    ,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n    ,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n    ,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n    ,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n    ,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n    ,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n输出:false\n解释:除了第一行的第一个数字从 5 改为 8 以外,空格内其他数字均与 示例1 相同。 但由于位于左上角的 3x3 宫内有两个 8 存在, 因此这个数独是无效的。
    \n

     

    \n

    提示:

    \n
      \n
    • board.length == 9
    • \n
    • board[i].length == 9
    • \n
    • board[i][j] 是一位数字或者 '.'
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600469920", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tbool isValidSudoku(vector> &board)\n\t{\n\t\tfor (int i = 0; i < board.size(); i++)\n\t\t{\n\t\t\tvector mark(10);\n\t\t\tfor (int j = 0; j < board.size(); j++)\n\t\t\t{\n\t\t\t\tif (!valid(board, mark, i, j))\n\t\t\t\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int j = 0; j < board.size(); j++)\n\t\t{\n\t\t\tvector mark(10);\n\t\t\tfor (int i = 0; i < board.size(); i++)\n\t\t\t{\n\t\t\t\tif (!valid(board, mark, i, j))\n\t\t\t\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int k = 0; k < board.size(); k++)\n\t\t{\n\t\t\tint sr = k / 3 * 3;\n\t\t\tint sc = (k % 3) * 3;\n\t\t\tvector mark(10);\n\t\t\tfor (int i = sr; i < sr + 3; i++)\n\t\t\t{\n\t\t\t\tfor (int j = sc; j < sc + 3; j++)\n\t\t\t\t{\n\t\t\t\t\tif (!valid(board, mark, i, j))\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\nprivate:\n\tbool valid(vector> &board, vector &mark, int i, int j)\n\t{\n\t\tif (board[i][j] != '.')\n\t\t{\n\t\t\tint index = board[i][j] - '0';\n\t\t\tif (mark[index])\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmark[index] = 1;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n};", + "java": "class Solution {\n\tpublic boolean isValidSudoku(char[][] board) {\n\t\tboolean[][] row = new boolean[9][9];\n\t\tboolean[][] col = new boolean[9][9];\n\t\tboolean[][] block = new boolean[9][9];\n\t\tfor (int i = 0; i < 9; i++) {\n\t\t\tfor (int j = 0; j < 9; j++) {\n\t\t\t\tif (board[i][j] != '.') {\n\t\t\t\t\tint num = board[i][j] - '1';\n\t\t\t\t\tint blockIndex = i / 3 * 3 + j / 3;\n\t\t\t\t\tif (row[i][num] || col[j][num] || block[blockIndex][num]) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\trow[i][num] = true;\n\t\t\t\t\t\tcol[j][num] = true;\n\t\t\t\t\t\tblock[blockIndex][num] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}", + "js": "", + "python": "from typing import List\nclass Solution:\n\tdef isValidSudoku(self, board):\n\t\t\"\"\"\n\t\t:type board: List[List[str]]\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\traw = [{},{},{},{},{},{},{},{},{}]\n\t\tcol = [{},{},{},{},{},{},{},{},{}]\n\t\tcell = [{},{},{},{},{},{},{},{},{}]\n\t\tfor i in range(9):\n\t\t\tfor j in range(9):\t\t\t\t\t\t\t\t \n\t\t\t\tnum = (3*(i//3) + j//3)\n\t\t\t\ttemp = board[i][j]\n\t\t\t\tif temp != \".\":\n\t\t\t\t\tif temp not in raw[i] and temp not in col[j] and temp not in cell[num]:\n\t\t\t\t\t\traw [i][temp] = 1\n\t\t\t\t\t\tcol [j][temp] = 1\n\t\t\t\t\t\tcell [num][temp] =1\n\t\t\t\t\telse:\n\t\t\t\t\t\treturn False\t\n\t\treturn True\n# %%\ns = Solution()\nboard = [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"]\n\t\t,[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"]\n\t\t,[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"]\n\t\t,[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"]\n\t\t,[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"]\n\t\t,[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"]\n\t\t,[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"]\n\t\t,[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"]\n\t\t,[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\nprint(s.isValidSudoku(board))", + "status": 1, + "keywords": "数组,哈希表,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_45176257/article/details/106487272" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/35/35_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/35/35_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/35/35_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/36.json b/data_backup/leetcode/36.json new file mode 100644 index 000000000..849bc4acd --- /dev/null +++ b/data_backup/leetcode/36.json @@ -0,0 +1,24 @@ +{ + "question_id": 37, + "question_title": "解数独", + "difficulty": "困难", + "question_content": "

    编写一个程序,通过填充空格来解决数独问题。

    \n

    数独的解法需 遵循如下规则

    \n
      \n
    1. 数字 1-9 在每一行只能出现一次。
    2. \n
    3. 数字 1-9 在每一列只能出现一次。
    4. \n
    5. 数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。(请参考示例图)
    6. \n
    \n

    数独部分空格内已填入了数字,空白格用 '.' 表示。

    \n

     

    \n
    \n
    \n
    \n

    示例:

    \n
    输入:board = \n    [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"],\n    [\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"],\n    [\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"],\n    [\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"],\n    [\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"],\n    [\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"],\n    [\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"],\n    [\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"],\n    [\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\n输出:\n    [[\"5\",\"3\",\"4\",\"6\",\"7\",\"8\",\"9\",\"1\",\"2\"],\n    [\"6\",\"7\",\"2\",\"1\",\"9\",\"5\",\"3\",\"4\",\"8\"],\n    [\"1\",\"9\",\"8\",\"3\",\"4\",\"2\",\"5\",\"6\",\"7\"],\n    [\"8\",\"5\",\"9\",\"7\",\"6\",\"1\",\"4\",\"2\",\"3\"],\n    [\"4\",\"2\",\"6\",\"8\",\"5\",\"3\",\"7\",\"9\",\"1\"],\n    [\"7\",\"1\",\"3\",\"9\",\"2\",\"4\",\"8\",\"5\",\"6\"],\n    [\"9\",\"6\",\"1\",\"5\",\"3\",\"7\",\"2\",\"8\",\"4\"],\n    [\"2\",\"8\",\"7\",\"4\",\"1\",\"9\",\"6\",\"3\",\"5\"],\n    [\"3\",\"4\",\"5\",\"2\",\"8\",\"6\",\"1\",\"7\",\"9\"]]\n解释:输入的数独如上图所示,唯一有效的解决方案如下所示:\n

     

    \n
    \n \n\n

     

    \n

    提示:

    \n
      \n
    • board.length == 9
    • \n
    • board[i].length == 9
    • \n
    • board[i][j] 是一位数字或者 '.'
    • \n
    • 题目数据 保证 输入数独仅有一个解
    • \n
    \n
    \n
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470827", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvoid solveSudoku(vector> &board)\n\t{\n\t\tint size = board.size();\n\t\tvector> rows(size, vector(10));\n\t\tvector> cols(size, vector(10));\n\t\tvector> boxes(size, vector(10));\n\t\tfor (int i = 0; i < size; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < size; j++)\n\t\t\t{\n\t\t\t\tif (board[i][j] != '.')\n\t\t\t\t{\n\t\t\t\t\tint num = board[i][j] - '0';\n\t\t\t\t\tint idx = i / 3 * 3 + j / 3;\n\t\t\t\t\trows[i][num] = true;\n\t\t\t\t\tcols[j][num] = true;\n\t\t\t\t\tboxes[idx][num] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdfs(board, 0, rows, cols, boxes);\n\t}\nprivate:\n\tbool valid(int num, int row, int col, int idx, vector> &rows,\n\t\t\t vector> &cols, vector> &boxes)\n\t{\n\t\treturn !rows[row][num] && !cols[col][num] && !boxes[idx][num];\n\t}\n\tbool dfs(vector> &board, int size, vector> &rows,\n\t\t\t vector> &cols, vector> &boxes)\n\t{\n\t\tif (size == 9 * 9)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbool ok = false;\n\t\t\tint row = size / 9;\n\t\t\tint col = size % 9;\n\t\t\tint idx = row / 3 * 3 + col / 3;\n\t\t\tif (board[row][col] == '.')\n\t\t\t{\n\t\t\t\tfor (int i = 1; i <= 9; i++)\n\t\t\t\t{\n\t\t\t\t\tif (valid(i, row, col, idx, rows, cols, boxes))\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[row][col] = i + '0';\n\t\t\t\t\t\trows[row][i] = true;\n\t\t\t\t\t\tcols[col][i] = true;\n\t\t\t\t\t\tboxes[idx][i] = true;\n\t\t\t\t\t\tok = dfs(board, size + 1, rows, cols, boxes);\n\t\t\t\t\t\tif (!ok)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trows[row][i] = false;\n\t\t\t\t\t\t\tcols[col][i] = false;\n\t\t\t\t\t\t\tboxes[idx][i] = false;\n\t\t\t\t\t\t\tboard[row][col] = '.';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tok = dfs(board, size + 1, rows, cols, boxes);\n\t\t\t}\n\t\t\treturn ok;\n\t\t}\n\t}\n};", + "java": "class Solution {\n\n\tboolean row[][] = new boolean[9][9];\n\tboolean col[][] = new boolean[9][9];\n\n\tboolean cell[][][] = new boolean[3][3][9];\n\n\tpublic void solveSudoku(char[][] board) {\n\n\t\tfor (int i = 0; i < 9; i++) {\n\t\t\tfor (int j = 0; j < 9; j++) {\n\t\t\t\tif (board[i][j] != '.') {\n\n\t\t\t\t\tint t = board[i][j] - '1';\n\n\t\t\t\t\trow[i][t] = col[j][t] = cell[i / 3][j / 3][t] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdfs(board, 0, 0);\n\t}\n\n\tpublic boolean dfs(char[][] board, int x, int y) {\n\n\t\tif (y == 9) {\n\n\t\t\tx++;\n\t\t\ty = 0;\n\t\t}\n\n\t\tif (x == 9)\n\t\t\treturn true;\n\n\t\tif (board[x][y] != '.')\n\t\t\treturn dfs(board, x, y + 1);\n\n\t\tfor (int num = 0; num < 9; num++) {\n\n\t\t\tif (!row[x][num] && !col[y][num] && !cell[x / 3][y / 3][num]) {\n\n\t\t\t\tboard[x][y] = (char) (num + '1');\n\t\t\t\trow[x][num] = col[y][num] = cell[x / 3][y / 3][num] = true;\n\n\t\t\t\tif (dfs(board, x, y + 1))\n\t\t\t\t\treturn true;\n\n\t\t\t\tboard[x][y] = '.';\n\t\t\t\trow[x][num] = col[y][num] = cell[x / 3][y / 3][num] = false;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef solveSudoku(self, board):\n\t\t\tdef isvaild(i,j):\n\t\t\t\tfor m in range(9):\n\t\t\t\t\tif m!=i and board[m][j]==board[i][j]:\n\t\t\t\t\t\treturn False\n\t\t\t\tfor n in range(9):\n\t\t\t\t\tif n!=j and board[i][n]==board[i][j]:\n\t\t\t\t\t\treturn False\n\t\t\t\tfor m in range(i//3*3,i//3*3+3):\n\t\t\t\t\tfor n in range(j//3*3,j//3*3+3):\n\t\t\t\t\t\tif m!=i and n!=j and board[m][n]==board[i][j]:\n\t\t\t\t\t\t\treturn False\n\t\t\t\treturn True\n\t\t\tdef f(a,b,board):\n\t\t\t\tfor i in range(a,9):\n\t\t\t\t\tfor j in range(b,9):\n\t\t\t\t\t\tif board[i][j]=='.':\n\t\t\t\t\t\t\tfor c in '123456789':\n\t\t\t\t\t\t\t\tboard[i][j]=c\n\t\t\t\t\t\t\t\tif isvaild(i,j):\n\t\t\t\t\t\t\t\t\tif f(a,b,board):return True\n\t\t\t\t\t\t\t\t\telse: board[i][j] = '.'\n\t\t\t\t\t\t\t\telse:board[i][j] = '.'\n\t\t\t\t\t\t\treturn False\n\t\t\t\treturn True\n\t\t\tf(0,0,board)\n\t\t\treturn board\n# %%\ns = Solution()\nboard = [[\"5\",\"3\",\".\",\".\",\"7\",\".\",\".\",\".\",\".\"],[\"6\",\".\",\".\",\"1\",\"9\",\"5\",\".\",\".\",\".\"],[\".\",\"9\",\"8\",\".\",\".\",\".\",\".\",\"6\",\".\"],[\"8\",\".\",\".\",\".\",\"6\",\".\",\".\",\".\",\"3\"],[\"4\",\".\",\".\",\"8\",\".\",\"3\",\".\",\".\",\"1\"],[\"7\",\".\",\".\",\".\",\"2\",\".\",\".\",\".\",\"6\"],[\".\",\"6\",\".\",\".\",\".\",\".\",\"2\",\"8\",\".\"],[\".\",\".\",\".\",\"4\",\"1\",\"9\",\".\",\".\",\"5\"],[\".\",\".\",\".\",\".\",\"8\",\".\",\".\",\"7\",\"9\"]]\nprint(s.solveSudoku(board))", + "status": 1, + "keywords": "数组,回溯,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/36/36_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/36/36_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/36/36_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/37.json b/data_backup/leetcode/37.json new file mode 100644 index 000000000..83f1886a9 --- /dev/null +++ b/data_backup/leetcode/37.json @@ -0,0 +1,24 @@ +{ + "question_id": 38, + "question_title": "外观数列", + "difficulty": "中等", + "question_content": "
    \n

    给定一个正整数 n ,输出外观数列的第 n 项。

    \n\n

    「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。

    \n\n

    你可以将其视作是由递归公式定义的数字字符串序列:

    \n\n
      \n
    • countAndSay(1) = \"1\"
    • \n
    • countAndSay(n) 是对 countAndSay(n-1) 的描述,然后转换成另一个数字字符串。
    • \n
    \n\n

    前五项如下:

    \n\n
    \n    1.     1\n    2.     11\n    3.     21\n    4.     1211\n    5.     111221\n    第一项是数字 1 \n    描述前一项,这个数是 1 即 “ 一 个 1 ”,记作 \"11\"\n    描述前一项,这个数是 11 即 “ 二 个 1 ” ,记作 \"21\"\n    描述前一项,这个数是 21 即 “ 一 个 2 + 一 个 1 ” ,记作 \"1211\"\n    描述前一项,这个数是 1211 即 “ 一 个 1 + 一 个 2 + 二 个 1 ” ,记作 \"111221\"\n    
    \n\n

    描述 一个数字字符串,首先要将字符串分割为 最小 数量的组,每个组都由连续的最多 相同字符\n 组成。然后对于每个组,先描述字符的数量,然后描述字符,形成一个描述组。要将描述转换为数字字符串,先将每组中的字符数量用数字替换,再将所有描述组连接起来。

    \n\n

    例如,数字字符串 \"3322251\" 的描述如下图:

    \n \"\"\n\n
      \n
    \n\n

     

    \n\n

    示例 1:

    \n\n
    输入:n = 1\n输出:\"1\"\n解释:这是一个基本样例。\n
    \n\n

    示例 2:

    \n\n
    输入:n = 4\n输出:\"1211\"\n解释:\ncountAndSay(1) = \"1\"\ncountAndSay(2) = 读 \"1\" = 一 个 1 = \"11\"\ncountAndSay(3) = 读 \"11\" = 二 个 1 = \"21\"\ncountAndSay(4) = 读 \"21\" = 一 个 2 + 一 个 1 = \"12\" + \"11\" = \"1211\"\n
    \n\n

     

    \n\n

    提示:

    \n\n
      \n
    • 1 <= n <= 30
    • \n
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470795", + "cpp": "#include \n#include \n#include \nstatic void parse(char *input, char *output)\n{\n\tchar *p = input;\n\tchar *q = output;\n\twhile (*p != '\\0')\n\t{\n\t\tint count = 1;\n\t\twhile (p[0] == p[1])\n\t\t{\n\t\t\tcount++;\n\t\t\tp++;\n\t\t}\n\t\tint n = 0;\n\t\twhile (count > 0)\n\t\t{\n\t\t\tn += count % 10;\n\t\t\tcount /= 10;\n\t\t}\n\t\twhile (n > 0)\n\t\t{\n\t\t\t*q++ = (n % 10) + '0';\n\t\t\tn /= 10;\n\t\t}\n\t\t*q++ = p[0];\n\t\tp++;\n\t}\n\t*q = '\\0';\n}\nstatic char *countAndSay(int n)\n{\n\tif (n < 1)\n\t{\n\t\treturn NULL;\n\t}\n\tchar *result;\n\tchar *prev = malloc(10000);\n\tchar *next = malloc(10000);\n\tstrcpy(prev, \"1\");\n\tif (n == 1)\n\t{\n\t\treturn prev;\n\t}\n\tint i;\n\tfor (i = 2; i <= n; i++)\n\t{\n\t\tif (i & 0x1)\n\t\t{\n\t\t\tparse(next, prev);\n\t\t\tresult = prev;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tparse(prev, next);\n\t\t\tresult = next;\n\t\t}\n\t}\n\treturn result;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test n\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", countAndSay(atoi(argv[1])));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic String countAndSay(int n) {\n\t\tString pre = \"1\";\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tStringBuilder temp = new StringBuilder();\n\t\t\tchar c = pre.charAt(0);\n\t\t\tint cnt = 1;\n\t\t\tfor (int j = 1; j < pre.length(); j++) {\n\t\t\t\tchar cc = pre.charAt(j);\n\t\t\t\tif (c == cc) {\n\t\t\t\t\tcnt++;\n\t\t\t\t} else {\n\t\t\t\t\ttemp.append(cnt).append(c);\n\t\t\t\t\tcnt = 1;\n\t\t\t\t\tc = cc;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttemp.append(cnt).append(c);\n\t\t\tpre = temp.toString();\n\t\t}\n\t\treturn pre;\n\t}\n}", + "js": "", + "python": "class Solution:\n\tdef countAndSay(self, n):\n\t\tif n == 1:\n\t\t\treturn '1'\n\t\tx = '1'\n\t\twhile n > 1:\n\t\t\tx = self.count(x)\n\t\t\tn -= 1\n\t\treturn x\n\tdef count(self, x):\n\t\tm = list(x)\n\t\tres = []\n\t\tm.append(None)\n\t\ti , j = 0 , 0\n\t\twhile i < len(m) - 1:\n\t\t\tj += 1\n\t\t\tif m[j] != m[i]:\n\t\t\t\tres += [j - i, m[i]]\n\t\t\t\ti = j\n\t\treturn ''.join(str(s) for s in res)\n# %%\ns = Solution()\nprint(s.countAndSay(n = 4))", + "status": 1, + "keywords": "字符串", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104314641" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/37/37_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/37/37_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/37/37_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/38.json b/data_backup/leetcode/38.json new file mode 100644 index 000000000..6a1d662b0 --- /dev/null +++ b/data_backup/leetcode/38.json @@ -0,0 +1,24 @@ +{ + "question_id": 39, + "question_title": "组合总和", + "difficulty": "中等", + "question_content": "

    给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。\n

    \n

    candidates 中的数字可以无限制重复被选取。

    \n

    说明:

    \n
      \n
    • 所有数字(包括 target)都是正整数。
    • \n
    • 解集不能包含重复的组合。 
    • \n
    \n

    示例 1:

    \n
    输入:candidates = [2,3,6,7], target = 7,
    输出:
    [[7],[2,2,3]]
    \n

    示例 2:

    \n
    输入:candidates = [2,3,5], target = 8,
    输出:
    [[2,2,2,2],[2,3,3],[3,5]]
    \n

     

    \n

    提示:

    \n
      \n
    • 1 <= candidates.length <= 30
    • \n
    • 1 <= candidates[i] <= 200
    • \n
    • candidate 中的每个元素都是独一无二的。
    • \n
    • 1 <= target <= 500
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600471017", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> combinationSum(vector &candidates, int target)\n\t{\n\t\tvector> res;\n\t\tdfs(candidates, 0, target, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(vector &candidates, int start, int target, vector> &res)\n\t{\n\t\tif (target < 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\telse if (target == 0)\n\t\t{\n\t\t\tres.push_back(stack);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = start; i < candidates.size(); i++)\n\t\t\t{\n\t\t\t\tstack.push_back(candidates[i]);\n\t\t\t\tdfs(candidates, i, target - candidates[i], res);\n\t\t\t\tstack.pop_back();\n\t\t\t}\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic List> combinationSum(int[] candiates, int target) {\n\n\t\tList> resultList = new ArrayList<>();\n\n\t\tList result = new ArrayList<>();\n\n\t\tArrays.sort(candiates);\n\n\t\tdfs(candiates, resultList, result, 0, target);\n\t\treturn resultList;\n\n\t}\n\n\tprivate void dfs(int[] candiates, List> resultList, List result, int start, int target) {\n\n\t\tif (target < 0) {\n\t\t\treturn;\n\t\t}\n\n\t\telse if (target == 0) {\n\n\t\t\tresultList.add(new ArrayList<>(result));\n\t\t} else {\n\t\t\tfor (int i = start; i < candiates.length; i++) {\n\t\t\t\tresult.add(candiates[i]);\n\n\t\t\t\tdfs(candiates, resultList, result, i, target - candiates[i]);\n\n\t\t\t\tresult.remove(result.size() - 1);\n\t\t\t}\n\t\t}\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef combinationSum(self, candidates, target):\n\t\tcandidates.sort()\n\t\tdp = [[] for _ in range(target + 1)]\n\t\tdp[0].append([])\n\t\tfor i in range(1, target + 1):\n\t\t\tfor j in range(len(candidates)):\n\t\t\t\tif candidates[j] > i:\n\t\t\t\t\tbreak\n\t\t\t\tfor k in range(len(dp[i - candidates[j]])):\n\t\t\t\t\ttemp = dp[i - candidates[j]][k][:]\n\t\t\t\t\tif len(temp) > 0 and temp[-1] > candidates[j]:\n\t\t\t\t\t\tcontinue\n\t\t\t\t\ttemp.append(candidates[j])\n\t\t\t\t\tdp[i].append(temp)\n\t\treturn dp[target]\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.combinationSum([8,7,4,3], 11))", + "status": 1, + "keywords": "数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/38/38_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/38/38_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/38/38_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/39.json b/data_backup/leetcode/39.json new file mode 100644 index 000000000..2a1a676e1 --- /dev/null +++ b/data_backup/leetcode/39.json @@ -0,0 +1,24 @@ +{ + "question_id": 40, + "question_title": "组合总和 II", + "difficulty": "中等", + "question_content": "

    给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。\n

    \n

    candidates 中的每个数字在每个组合中只能使用一次。

    \n

    说明:

    \n
      \n
    • 所有数字(包括目标数)都是正整数。
    • \n
    • 解集不能包含重复的组合。 
    • \n
    \n

    示例 1:

    \n
    输入: candidates = [10,1,2,7,6,1,5], target = 8,
    所求解集为:
    [[1, 7],[1, 2, 5],[2, 6],[1, 1, 6]]
    \n

    示例 2:

    \n
    输入: candidates = [2,5,2,1,2], target = 5,
    所求解集为:
    [[1,2,2],[5]]
    ", + "topic_link": "https://bbs.csdn.net/topics/600470928", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> combinationSum2(vector &candidates, int target)\n\t{\n\t\tvector> res;\n\t\tsort(candidates.begin(), candidates.end());\n\t\tdfs(candidates, 0, target, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(vector &candidates, int start, int target, vector> &res)\n\t{\n\t\tif (target < 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\telse if (target == 0)\n\t\t{\n\t\t\tres.push_back(stack);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint last = INT_MIN;\n\t\t\tfor (int i = start; i < candidates.size(); i++)\n\t\t\t{\n\t\t\t\tif (last != candidates[i])\n\t\t\t\t{\n\t\t\t\t\tstack.push_back(candidates[i]);\n\t\t\t\t\tdfs(candidates, i + 1, target - candidates[i], res);\n\t\t\t\t\tstack.pop_back();\n\t\t\t\t}\n\t\t\t\tlast = candidates[i];\n\t\t\t}\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic List> combinationSum2(int[] candidates, int target) {\n\t\tArrays.sort(candidates);\n\t\tList> res = new ArrayList>();\n\t\tif (candidates.length == 0 || target < candidates[0])\n\t\t\treturn res;\n\t\tList tmp = new ArrayList();\n\t\thelper(candidates, target, 0, tmp, res);\n\t\treturn res;\n\t}\n\n\tpublic void helper(int[] a, int target, int start, List tmp, List> res) {\n\t\tif (target < 0)\n\t\t\treturn;\n\t\tif (target == 0) {\n\t\t\tres.add(new ArrayList(tmp));\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = start; i < a.length; i++) {\n\t\t\ttmp.add(a[i]);\n\t\t\tint newtarget = target - a[i];\n\t\t\thelper(a, newtarget, i + 1, tmp, res);\n\t\t\ttmp.remove(tmp.size() - 1);\n\t\t\tif (newtarget <= 0)\n\t\t\t\tbreak;\n\t\t\twhile (i + 1 < a.length && a[i] == a[i + 1])// 组合中有重复元素,不要重复开头\n\t\t\t\ti++;\n\t\t}\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef combinationSum2(self, candidates, target):\n\t\t\"\"\"\n\t\t:type candidates: List[int]\n\t\t:type target: int\n\t\t:rtype: List[List[int]]\n\t\t\"\"\"\n\t\tcandidates.sort()\n\t\tdp = [[] for _ in range(target + 1)]\n\t\tdp[0].append([])\n\t\tfor i in range(1, target + 1):\n\t\t\tfor j in range(len(candidates)):\n\t\t\t\tif candidates[j] > i:\n\t\t\t\t\tbreak\n\t\t\t\tfor k in range(len(dp[i - candidates[j]])):\n\t\t\t\t\ttemp = dp[i - candidates[j]][k][:]\n\t\t\t\t\tif len(temp) > 0 and temp[-1] >= j:\n\t\t\t\t\t\tcontinue\n\t\t\t\t\ttemp.append(j)\n\t\t\t\t\tdp[i].append(temp)\n\t\tres = []\n\t\tcheck = {}\n\t\tfor temp in dp[target]:\n\t\t\tvalue = [candidates[t] for t in temp]\n\t\t\ttry:\n\t\t\t\tcheck[str(value)] += 1\n\t\t\texcept KeyError:\n\t\t\t\tcheck[str(value)] = 1\n\t\t\t\tres.append(value)\n\t\treturn res\n# %%\ns = Solution()\nprint(s.combinationSum2(candidates = [2,5,2,1,2], target = 5))", + "status": 1, + "keywords": "数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/39/39_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/39/39_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/39/39_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/4.json b/data_backup/leetcode/4.json new file mode 100644 index 000000000..06183883e --- /dev/null +++ b/data_backup/leetcode/4.json @@ -0,0 +1,24 @@ +{ + "question_id": 5, + "question_title": "最长回文子串", + "difficulty": "中等", + "question_content": "

    给你一个字符串 s,找到 s 中最长的回文子串。

     

    示例 1:

    输入:s = \"babad\"
    输出:
    \"bab\"
    解释:
    \"aba\" 同样是符合题意的答案。

    示例 2:

    输入:s = \"cbbd\"
    输出:
    \"bb\"

    示例 3:

    输入:s = \"a\"
    输出:
    \"a\"

    示例 4:

    输入:s = \"ac\"
    输出:
    \"a\"

     

    提示:

      \t
    • 1 <= s.length <= 1000
    • \t
    • s 仅由数字和英文字母(大写和/或小写)组成
    ", + "topic_link": "https://bbs.csdn.net/topics/600470834", + "cpp": "class Solution\n{\npublic:\n\tstring longestPalindrome(string s)\n\t{\n\t\tint ti = 0, maxlen = 0, i, t;\n\t\tfor (i = 0; s[i]; i++)\n\t\t{\n\t\t\tt = 1;\n\t\t\twhile (t <= i && s[i + t])\n\t\t\t{\n\t\t\t\tif (s[i + t] == s[i - t])\n\t\t\t\t\tt++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt--;\n\t\t\tif (2 * t + 1 > maxlen)\n\t\t\t{\n\t\t\t\tti = i - t;\n\t\t\t\tmaxlen = 2 * t + 1;\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; s[i]; i++)\n\t\t{\n\t\t\tt = 1;\n\t\t\twhile (t <= i + 1 && s[i + t])\n\t\t\t{\n\t\t\t\tif (s[i - t + 1] == s[i + t])\n\t\t\t\t\tt++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt--;\n\t\t\tif (2 * t > maxlen)\n\t\t\t{\n\t\t\t\tti = i - t + 1;\n\t\t\t\tmaxlen = 2 * t;\n\t\t\t}\n\t\t}\n\t\ts[ti + maxlen] = 0;\n\t\treturn s.c_str() + ti;\n\t}\n};", + "java": "class Solution {\n\tpublic String longestPalindrome(String s) {\n\t\tint ti = 0, maxlen = 0, i, t;\n\t\tfor (i = 0; i < s.length(); i++) {\n\t\t\tt = 1;\n\t\t\twhile (t <= i && i + t < s.length()) {\n\t\t\t\tif (s.charAt(i + t) == s.charAt(i - t))\n\t\t\t\t\tt++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt--;\n\t\t\tif (2 * t + 1 > maxlen) {\n\t\t\t\tti = i - t;\n\t\t\t\tmaxlen = 2 * t + 1;\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < s.length(); i++) {\n\t\t\tt = 1;\n\t\t\twhile (t <= i + 1 && i + t < s.length()) {\n\t\t\t\tif (s.charAt(i - t + 1) == s.charAt(i + t))\n\t\t\t\t\tt++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt--;\n\t\t\tif (2 * t > maxlen) {\n\t\t\t\tti = i - t + 1;\n\t\t\t\tmaxlen = 2 * t;\n\t\t\t}\n\t\t}\n\t\treturn s.substring(ti, ti + maxlen);\n\t}\n}", + "js": "/**\n * @param {string} s\n * @return {string}\n */\nvar longestPalindrome = function(s) {\n\tlet ti = 0;\n\tlet maxlen = 0;\n\tlet i, t;\n\n // odd length probe\n for (i = 0; s[i]; i++) {\n t = 1;\n while (t <= i && s[i + t]) {\n if (s[i + t] == s[i - t])\n t++;\n else\n break;\n }\n t--;\n if (2 * t + 1 > maxlen) {\n ti = i - t;\n maxlen = 2 * t + 1;\n }\n }\n\n // even length probe\n for (i = 0; s[i]; i++) {\n t = 1;\n while (t <= i + 1 && s[i + t]) {\n if (s[i - t + 1] == s[i + t])\n t++;\n else\n break;\n }\n t--;\n\n if (2 * t > maxlen) {\n ti = i - t + 1;\n maxlen = 2 * t;\n }\n }\n\n return s.substring(ti, ti + maxlen);\n}\n\nfunction main(){\n\tconst cases = [\n\t\t[\"cbbd\",\"bb\"],\n\t\t// ['a','a'],\n\t\t// ['bab','bab'],\n\t\t// ['baab','baab'],\n\t\t// ['babad','bab'],\n\t\t// ['bb','bb'],\n\t\t// ['cbbd','bb'],\n\t\t// ['cxxabbmxxd','xx'],\n\t\t// ['aaabaaaa','aaabaaa'],\n\t\t// ['zudfweormatjycujjirzjpyrmaxurectxrtqedmmgergwdvjmjtstdhcihacqnothgttgqfywcpgnuvwglvfiuxteopoyizgehkwuvvkqxbnufkcbodlhdmbqyghkojrgokpwdhtdrwmvdegwycecrgjvuexlguayzcammupgeskrvpthrmwqaqsdcgycdupykppiyhwzwcplivjnnvwhqkkxildtyjltklcokcrgqnnwzzeuqioyahqpuskkpbxhvzvqyhlegmoviogzwuiqahiouhnecjwysmtarjjdjqdrkljawzasriouuiqkcwwqsxifbndjmyprdozhwaoibpqrthpcjphgsfbeqrqqoqiqqdicvybzxhklehzzapbvcyleljawowluqgxxwlrymzojshlwkmzwpixgfjljkmwdtjeabgyrpbqyyykmoaqdambpkyyvukalbrzoyoufjqeftniddsfqnilxlplselqatdgjziphvrbokofvuerpsvqmzakbyzxtxvyanvjpfyvyiivqusfrsufjanmfibgrkwtiuoykiavpbqeyfsuteuxxjiyxvlvgmehycdvxdorpepmsinvmyzeqeiikajopqedyopirmhymozernxzaueljjrhcsofwyddkpnvcvzixdjknikyhzmstvbducjcoyoeoaqruuewclzqqqxzpgykrkygxnmlsrjudoaejxkipkgmcoqtxhelvsizgdwdyjwuumazxfstoaxeqqxoqezakdqjwpkrbldpcbbxexquqrznavcrprnydufsidakvrpuzgfisdxreldbqfizngtrilnbqboxwmwienlkmmiuifrvytukcqcpeqdwwucymgvyrektsnfijdcdoawbcwkkjkqwzffnuqituihjaklvthulmcjrhqcyzvekzqlxgddjoir','gykrkyg']\n\t];\n\n\tfor(const c of cases){\n\t\tconsole.log('input:',c[0],', expected result:',c[1]);\n\t\tconst v = longestPalindrome(c[0], 0);\n\t\tconsole.log('output:',v);\n\t\tconsole.assert(v===c[1]);\n\t}\t\n}\n\nmain();\n\n", + "python": "class Solution:\n\tdef longestPalindrome(self, s: str) -> str:\n\t\tti = 0\n\t\tmaxlen = 0\n\t\ti = 0\n\t\twhile i < len(s):\n\t\t\tt = 1\n\t\t\twhile t <= i and i + t < len(s):\n\t\t\t\tif s[i + t] == s[i - t]:\n\t\t\t\t\tt += 1\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\tt -= 1\n\t\t\tif 2 * t + 1 > maxlen:\n\t\t\t\tti = i - t\n\t\t\t\tmaxlen = 2 * t + 1\n\t\t\ti += 1\n\t\ti = 0\n\t\twhile i < len(s):\n\t\t\tt = 1\n\t\t\twhile t <= i + 1 and i + t < len(s):\n\t\t\t\tif s[i - t + 1] == s[i + t]:\n\t\t\t\t\tt += 1\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\tt -= 1\n\t\t\tif 2 * t > maxlen:\n\t\t\t\tti = i - t + 1\n\t\t\t\tmaxlen = 2 * t\n\t\t\ti += 1\n\t\treturn s[ti:ti+maxlen]\n# %%\ns = Solution()\nprint(s.longestPalindrome('babad'))\nprint(s.longestPalindrome('cbbd'))", + "status": 1, + "keywords": "字符串,动态规划", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/4/4_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/4/4_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/4/4_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/40.json b/data_backup/leetcode/40.json new file mode 100644 index 000000000..74ee3f598 --- /dev/null +++ b/data_backup/leetcode/40.json @@ -0,0 +1,24 @@ +{ + "question_id": 41, + "question_title": "缺失的第一个正数", + "difficulty": "困难", + "question_content": "

    给你一个未排序的整数数组 nums ,请你找出其中没有出现的最小的正整数。

     

    进阶:你可以实现时间复杂度为 O(n) 并且只使用常数级别额外空间的解决方案吗?

     

    示例 1:

    输入:nums = [1,2,0]
    输出:
    3

    示例 2:

    输入:nums = [3,4,-1,1]
    输出:
    2

    示例 3:

    输入:nums = [7,8,9,11,12]
    输出:
    1

     

    提示:

      \t
    • 0 <= nums.length <= 300
    • \t
    • -231 <= nums[i] <= 231 - 1
    ", + "topic_link": "https://bbs.csdn.net/topics/600470223", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint firstMissingPositive(vector &nums)\n\t{\n\t\tif (nums.size() == 0)\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\tint i = 0;\n\t\twhile (i < nums.size())\n\t\t{\n\t\t\tif (nums[i] > 0 && nums[i] != i + 1 && nums[i] - 1 < nums.size() && nums[nums[i] - 1] != nums[i])\n\t\t\t{\n\t\t\t\tswap(nums[i], nums[nums[i] - 1]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < nums.size(); i++)\n\t\t{\n\t\t\tif (nums[i] != i + 1)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn i + 1;\n\t}\n};", + "java": "class Solution {\n\tpublic int firstMissingPositive(int[] nums) {\n\t\tint n = nums.length;\n\t\tint contains = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (nums[i] == 1) {\n\t\t\t\tcontains++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (contains == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((nums[i] <= 0) || (nums[i] > n)) {\n\t\t\t\tnums[i] = 1;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = Math.abs(nums[i]);\n\t\t\tnums[a - 1] = -Math.abs(nums[a - 1]);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (nums[i] > 0) {\n\t\t\t\treturn i + 1;\n\t\t\t}\n\t\t}\n\t\treturn n + 1;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef firstMissingPositive(self, nums):\n\t\tls = len(nums)\n\t\tindex = 0\n\t\twhile index < ls:\n\t\t\tif nums[index] <= 0 or nums[index] > ls or nums[nums[index] - 1] == nums[index]:\n\t\t\t\tindex += 1\n\t\t\telse:\n\t\t\t\tpos = nums[index] - 1\n\t\t\t\tnums[index], nums[pos] = nums[pos], nums[index]\n\t\tres = 0\n\t\twhile res < ls and nums[res] == res + 1:\n\t\t\tres += 1\n\t\treturn res + 1\n# %%\ns = Solution()\nprint(s.firstMissingPositive(nums = [1,2,0]))", + "status": 1, + "keywords": "数组,哈希表", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/shinef/article/details/106982112" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/40/40_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/40/40_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/40/40_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/41.json b/data_backup/leetcode/41.json new file mode 100644 index 000000000..c6849b92b --- /dev/null +++ b/data_backup/leetcode/41.json @@ -0,0 +1,24 @@ +{ + "question_id": 42, + "question_title": "接雨水", + "difficulty": "困难", + "question_content": "

    给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。

     

    示例 1:

    输入:height = [0,1,0,2,1,0,1,3,2,1,2,1]
    输出:
    6
    解释:
    上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。

    示例 2:

    输入:height = [4,2,0,3,2,5]
    输出:
    9

     

    提示:

      \t
    • n == height.length
    • \t
    • 0 <= n <= 3 * 104
    • \t
    • 0 <= height[i] <= 105
    ", + "topic_link": "https://bbs.csdn.net/topics/600470120", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint trap(vector &height)\n\t{\n\t\tint res = 0;\n\t\tint left = 0, left_max = 0;\n\t\tint right = height.size() - 1, right_max = 0;\n\t\twhile (left < right)\n\t\t{\n\t\t\tif (height[left] < height[right])\n\t\t\t{\n\t\t\t\tif (height[left] > left_max)\n\t\t\t\t{\n\t\t\t\t\tleft_max = height[left];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres += left_max - height[left];\n\t\t\t\t}\n\t\t\t\tleft++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (height[right] > right_max)\n\t\t\t\t{\n\t\t\t\t\tright_max = height[right];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres += right_max - height[right];\n\t\t\t\t}\n\t\t\t\tright--;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n};", + "java": "class Solution {\n\tpublic int trap(int[] height) {\n\t\tif (height == null)\n\t\t\treturn 0;\n\t\tint len = height.length;\n\t\tif (len == 0)\n\t\t\treturn 0;\n\t\tint res = 0;\n\t\tint[] left_max = new int[len];\n\t\tint[] right_max = new int[len];\n\t\tleft_max[0] = height[0];\n\n\t\tfor (int i = 1; i < len; i++) {\n\t\t\tleft_max[i] = Math.max(height[i], left_max[i - 1]);\n\t\t}\n\t\tright_max[len - 1] = height[len - 1];\n\n\t\tfor (int i = len - 2; i >= 0; i--) {\n\t\t\tright_max[i] = Math.max(height[i], right_max[i + 1]);\n\t\t}\n\n\t\tfor (int i = 1; i < len - 1; i++) {\n\t\t\tres += Math.min(left_max[i], right_max[i]) - height[i];\n\t\t}\n\t\treturn res;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef trap(self, height):\n\t\tls = len(height)\n\t\tif ls == 0:\n\t\t\treturn 0\n\t\tres, left = 0, 0\n\t\twhile left < ls and height[left] == 0:\n\t\t\tleft += 1\n\t\tpos = left + 1\n\t\twhile pos < ls:\n\t\t\tif height[pos] >= height[left]:\n\t\t\t\tres += self.rain_water(height, left, pos)\n\t\t\t\tleft = pos\n\t\t\t\tpos += 1\n\t\t\telif pos == ls - 1:\n\t\t\t\tmax_value, max_index = 0, pos\n\t\t\t\tfor index in range(left + 1, ls):\n\t\t\t\t\tif height[index] > max_value:\n\t\t\t\t\t\tmax_value = height[index]\n\t\t\t\t\t\tmax_index = index\n\t\t\t\tres += self.rain_water(height, left, max_index)\n\t\t\t\tleft = max_index\n\t\t\t\tpos = left + 1\n\t\t\telse:\n\t\t\t\tpos += 1\n\t\treturn res\n\tdef rain_water(self, height, start, end):\n\t\tif end - start <= 1:\n\t\t\treturn 0\n\t\tmin_m = min(height[start], height[end])\n\t\tres = min_m * (end - start - 1)\n\t\tstep = 0\n\t\tfor index in range(start + 1, end):\n\t\t\tif height[index] > 0:\n\t\t\t\tstep += height[index]\n\t\treturn res - step\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.trap([2,6,3,8,2,7,2,5,0]))", + "status": 1, + "keywords": "栈,数组,双指针,动态规划,单调栈", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/41/41_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/41/41_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/41/41_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/42.json b/data_backup/leetcode/42.json new file mode 100644 index 000000000..a6ea5712a --- /dev/null +++ b/data_backup/leetcode/42.json @@ -0,0 +1,24 @@ +{ + "question_id": 43, + "question_title": "字符串相乘", + "difficulty": "中等", + "question_content": "

    给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式。

    示例 1:

    输入: num1 = "2", num2 = "3"
    输出:
    "6"

    示例 2:

    输入: num1 = "123", num2 = "456"
    输出:
    "56088"

    说明:

      \t
    1. num1 和 num2 的长度小于110。
    2. \t
    3. num1 和 num2 只包含数字 0-9
    4. \t
    5. num1 和 num2 均不以零开头,除非是数字 0 本身。
    6. \t
    7. 不能使用任何标准库的大数类型(比如 BigInteger)直接将输入转换为整数来处理
    ", + "topic_link": "https://bbs.csdn.net/topics/600471020", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tstring multiply(string num1, string num2)\n\t{\n\t\tstring res(num1.length() + num2.length(), '0');\n\t\tfor (int i = num2.length() - 1; i >= 0; i--)\n\t\t{\n\t\t\tint j, carry = 0;\n\t\t\tfor (j = num1.length() - 1; j >= 0; j--)\n\t\t\t{\n\t\t\t\tcarry += (num1[j] - '0') * (num2[i] - '0') + (res[i + j + 1] - '0');\n\t\t\t\tres[i + j + 1] = carry % 10 + '0';\n\t\t\t\tcarry /= 10;\n\t\t\t}\n\t\t\tres[i + j + 1] = carry + '0';\n\t\t}\n\t\tint i;\n\t\tfor (i = 0; i < res.length() - 1; i++)\n\t\t{\n\t\t\tif (res[i] != '0')\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn res.substr(i);\n\t}\n};", + "java": "class Solution {\n\tpublic String multiply(String num1, String num2) {\n\t\tif (num1.equals(\"0\") || num2.equals(\"0\"))\n\t\t\treturn \"0\";\n\n\t\tint m = num1.length();\n\t\tint n = num2.length();\n\n\t\tint[] intRes = new int[m + n - 1];\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tintRes[i + j] += (num1.charAt(i) - 48) * (num2.charAt(j) - 48);\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = intRes.length - 1; i > 0; i--) {\n\t\t\tif (intRes[i] >= 10) {\n\t\t\t\tintRes[i - 1] += intRes[i] / 10;\n\t\t\t\tintRes[i] %= 10;\n\t\t\t}\n\t\t}\n\n\t\tString res = \"\";\n\t\tfor (int i = 0; i < intRes.length; i++) {\n\t\t\tres += String.valueOf(intRes[i]);\n\t\t}\n\t\treturn res;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef multiply(self, num1, num2):\n\t\tif num1 == '0' or num2 == '0':\n\t\t\treturn '0'\n\t\tres = ''\n\t\tls1, ls2, = len(num1), len(num2)\n\t\tls = ls1 + ls2\n\t\tarr = [0] * ls\n\t\tfor i in reversed(range(ls1)):\n\t\t\tfor j in reversed(range(ls2)):\n\t\t\t\tarr[i + j + 1] += int(num1[i]) * int(num2[j])\n\t\tfor i in reversed(range(1, ls)):\n\t\t\tarr[i - 1] += arr[i] / 10\n\t\t\tarr[i] %= 10\n\t\tpos = 0\n\t\tif arr[pos] == 0:\n\t\t\tpos += 1\n\t\twhile pos < ls:\n\t\t\tres = res + str(arr[pos])\n\t\t\tpos += 1\n\t\treturn res\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.multiply(\"98\", \"9\"))", + "status": 1, + "keywords": "数学,字符串,模拟", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/42/42_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/42/42_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/42/42_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/43.json b/data_backup/leetcode/43.json new file mode 100644 index 000000000..8f50ebc89 --- /dev/null +++ b/data_backup/leetcode/43.json @@ -0,0 +1,24 @@ +{ + "question_id": 44, + "question_title": "通配符匹配", + "difficulty": "困难", + "question_content": "

    给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配。

    '?' 可以匹配任何单个字符。'*' 可以匹配任意字符串(包括空字符串)。

    两个字符串完全匹配才算匹配成功。

    说明:

      \t
    • s 可能为空,且只包含从 a-z 的小写字母。
    • \t
    • p 可能为空,且只包含从 a-z 的小写字母,以及字符 ? 和 *

    示例 1:

    输入:s = "aa"p = "a"
    输出:
    false
    解释:
    "a" 无法匹配 "aa" 整个字符串。

    示例 2:

    输入:s = "aa"p = "*"
    输出:
    true
    解释:
     '*' 可以匹配任意字符串。

    示例 3:

    输入:s = "cb"p = "?a"
    输出:
    false
    解释:
     '?' 可以匹配 'c', 但第二个 'a' 无法匹配 'b'。

    示例 4:

    输入:s = "adceb"p = "*a*b"
    输出:
    true
    解释:
     第一个 '*' 可以匹配空字符串, 第二个 '*' 可以匹配字符串 "dce".

    示例 5:

    输入:s = "acdcb"p = "a*c?b"
    输出:
    false
    ", + "topic_link": "https://bbs.csdn.net/topics/600471019", + "cpp": "#include \n#include \n#include \n#include \nstatic bool isMatch(char *s, char *p)\n{\n\tchar *last_s = NULL;\n\tchar *last_p = NULL;\n\twhile (*s != '\\0')\n\t{\n\t\tif (*p == '*')\n\t\t{\n\t\t\tif (*++p == '\\0')\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tlast_s = s;\n\t\t\tlast_p = p;\n\t\t}\n\t\telse if (*p == '?' || *s == *p)\n\t\t{\n\t\t\ts++;\n\t\t\tp++;\n\t\t}\n\t\telse if (last_s != NULL)\n\t\t{\n\t\t\tp = last_p;\n\t\t\ts = ++last_s;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\twhile (*p == '*')\n\t{\n\t\tp++;\n\t}\n\treturn *p == '\\0';\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test string pattern\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", isMatch(argv[1], argv[2]) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean isMatch(String s, String p) {\n\t\tboolean[][] value = new boolean[p.length() + 1][s.length() + 1];\n\t\tvalue[0][0] = true;\n\t\tfor (int i = 1; i <= s.length(); i++) {\n\t\t\tvalue[0][i] = false;\n\t\t}\n\t\tfor (int i = 1; i <= p.length(); i++) {\n\t\t\tif (p.charAt(i - 1) == '*') {\n\t\t\t\tvalue[i][0] = value[i - 1][0];\n\t\t\t\tfor (int j = 1; j <= s.length(); j++) {\n\t\t\t\t\tvalue[i][j] = (value[i][j - 1] || value[i - 1][j]);\n\t\t\t\t}\n\t\t\t} else if (p.charAt(i - 1) == '?') {\n\t\t\t\tvalue[i][0] = false;\n\t\t\t\tfor (int j = 1; j <= s.length(); j++) {\n\t\t\t\t\tvalue[i][j] = value[i - 1][j - 1];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tvalue[i][0] = false;\n\t\t\t\tfor (int j = 1; j <= s.length(); j++) {\n\t\t\t\t\tvalue[i][j] = s.charAt(j - 1) == p.charAt(i - 1) && value[i - 1][j - 1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn value[p.length()][s.length()];\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef isMatch(self, s, p):\n\t\t\"\"\"\n\t\t:type s: str\n\t\t:type p: str\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\ts_index, p_index = 0, 0\n\t\tstar, s_star = -1, 0\n\t\ts_len, p_len = len(s), len(p)\n\t\twhile s_index < s_len:\n\t\t\tif p_index < p_len and (s[s_index] == p[p_index] or p[p_index] == '?'):\n\t\t\t\ts_index += 1\n\t\t\t\tp_index += 1\n\t\t\telif p_index < p_len and p[p_index] == '*':\n\t\t\t\tstar = p_index\n\t\t\t\ts_star = s_index\n\t\t\t\tp_index += 1\n\t\t\telif star != -1:\n\t\t\t\tp_index = star + 1\n\t\t\t\ts_star += 1\n\t\t\t\ts_index = s_star\n\t\t\telse:\n\t\t\t\treturn False\n\t\twhile p_index < p_len and p[p_index] == '*':\n\t\t\tp_index += 1\n\t\treturn p_index == p_len\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.isMatch(s = \"aa\",p = \"a\"))", + "status": 1, + "keywords": "贪心,递归,字符串,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104317836" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/43/43_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/43/43_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/43/43_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/44.json b/data_backup/leetcode/44.json new file mode 100644 index 000000000..80126d3ea --- /dev/null +++ b/data_backup/leetcode/44.json @@ -0,0 +1,24 @@ +{ + "question_id": 45, + "question_title": "跳跃游戏 II", + "difficulty": "中等", + "question_content": "

    给定一个非负整数数组,你最初位于数组的第一个位置。

    \n

    数组中的每个元素代表你在该位置可以跳跃的最大长度。

    \n

    你的目标是使用最少的跳跃次数到达数组的最后一个位置。

    \n

    示例:

    \n
    输入: [2,3,1,1,4]
    输出:
    2
    解释:
    跳到最后一个位置的最小跳跃数是 2。从下标为 0 跳到下标为 1 的位置,跳 1 步,然后跳 3 步到达数组的最后一个位置。
    \n

    说明:

    \n

    假设你总是可以到达数组的最后一个位置。

    ", + "topic_link": "https://bbs.csdn.net/topics/600469921", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint jump(vector &nums)\n\t{\n\t\tint steps = 0;\n\t\tint lo = 0, hi = 0;\n\t\twhile (hi < nums.size() - 1)\n\t\t{\n\t\t\tint right = 0;\n\t\t\tfor (int i = lo; i <= hi; i++)\n\t\t\t{\n\t\t\t\tright = max(i + nums[i], right);\n\t\t\t}\n\t\t\tlo = hi + 1;\n\t\t\thi = right;\n\t\t\tsteps++;\n\t\t}\n\t\treturn steps;\n\t}\n};", + "java": "class Solution {\n\tpublic int jump(int[] nums) {\n\t\tint end = 0;\n\t\tint steps = 0;\n\t\tint maxPosition = 0;\n\t\tfor (int i = 0; i < nums.length - 1; i++) {\n\n\t\t\tmaxPosition = Math.max(maxPosition, i + nums[i]);\n\n\t\t\tif (i == end) {\n\t\t\t\tend = maxPosition;\n\t\t\t\tsteps++;\n\t\t\t}\n\t\t}\n\t\treturn steps;\n\t}\n}\n", + "js": "", + "python": "class Solution:\n\tdef jump(self, nums):\n\t\tif len(nums) <= 1:\n\t\t\treturn 0\n\t\tend = 0 + nums[0]\n\t\tstart = 0\n\t\tstep = 1\n\t\tmaxDis = 0 + nums[0]\n\t\twhile end < len(nums) - 1:\n\t\t\tfor i in range(start + 1, end + 1):\n\t\t\t\tmaxDis = max(maxDis, nums[i] + i)\n\t\t\tstart = end\n\t\t\tend = maxDis\n\t\t\tstep += 1\n\t\treturn step\n# %%\ns = Solution()\nprint(s.jump(nums = [2,3,0,1,4]))", + "status": 1, + "keywords": "贪心,数组,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/44/44_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/44/44_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/44/44_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/45.json b/data_backup/leetcode/45.json new file mode 100644 index 000000000..af88a8ca7 --- /dev/null +++ b/data_backup/leetcode/45.json @@ -0,0 +1,24 @@ +{ + "question_id": 46, + "question_title": "全排列", + "difficulty": "中等", + "question_content": "

    给定一个 没有重复 数字的序列,返回其所有可能的全排列。

    示例:

    输入: [1,2,3]
    输出:
    [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]
    ", + "topic_link": "https://bbs.csdn.net/topics/600469820", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> permute(vector &nums)\n\t{\n\t\tvector> res;\n\t\tvector used(nums.size());\n\t\tdfs(nums, used, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(vector &nums, vector &used, vector> &res)\n\t{\n\t\tif (stack.size() == nums.size())\n\t\t{\n\t\t\tres.push_back(stack);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = 0; i < nums.size(); i++)\n\t\t\t{\n\t\t\t\tif (!used[i])\n\t\t\t\t{\n\t\t\t\t\tused[i] = true;\n\t\t\t\t\tstack.push_back(nums[i]);\n\t\t\t\t\tdfs(nums, used, res);\n\t\t\t\t\tstack.pop_back();\n\t\t\t\t\tused[i] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic List> permute(int[] nums) {\n\n\t\tList> result = new ArrayList>();\n\t\tArrays.sort(nums);\n\t\tList first = new ArrayList();\n\t\tfor (int r = 0; r < nums.length; r++) {\n\t\t\tfirst.add(nums[r]);\n\t\t}\n\t\tresult.add(first);\n\t\tint i = nums.length - 2;\n\t\twhile (i >= 0) {\n\t\t\tif (nums[i] < nums[i + 1]) {\n\t\t\t\tint temp = nums[i];\n\t\t\t\tfor (int j = nums.length - 1; j > i; j--) {\n\t\t\t\t\tif (nums[j] > temp) {\n\t\t\t\t\t\tnums[i] = nums[j];\n\t\t\t\t\t\tnums[j] = temp;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnums = quick_sort(nums, i + 1, nums.length - 1);\n\t\t\t\tList sub = new ArrayList();\n\t\t\t\tfor (int t = 0; t < nums.length; t++) {\n\t\t\t\t\tsub.add(nums[t]);\n\t\t\t\t}\n\t\t\t\tresult.add(sub);\n\t\t\t\ti = nums.length - 2;\n\n\t\t\t} else {\n\t\t\t\ti--;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\n\t}\n\n\tpublic int[] quick_sort(int[] a, int left, int right) {\n\t\tif (left < right) {\n\t\t\tint l = left;\n\t\t\tint r = right;\n\t\t\tint temp = a[l];\n\t\t\twhile (l != r) {\n\t\t\t\twhile (l < r && a[r] > temp) {\n\t\t\t\t\tr--;\n\t\t\t\t}\n\t\t\t\tif (l < r) {\n\t\t\t\t\ta[l] = a[r];\n\t\t\t\t\tl++;\n\t\t\t\t}\n\n\t\t\t\twhile (l < r && a[l] < temp) {\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\t\tif (l < r) {\n\t\t\t\t\ta[r] = a[l];\n\t\t\t\t\tr--;\n\t\t\t\t}\n\n\t\t\t}\n\t\t\ta[l] = temp;\n\t\t\tquick_sort(a, left, l - 1);\n\t\t\tquick_sort(a, l + 1, right);\n\t\t}\n\t\treturn a;\n\t}\n}", + "js": "", + "python": "class Solution:\n\t def permute(self, nums):\n\t\t\te=[]\n\t\t\tif(len(nums)==1):\n\t\t\t\treturn [nums]\n\t\t\tfor i in range(len(nums)):\n\t\t\t\tq=self.permute(nums[:i]+nums[i+1:])\n\t\t\t\tfor c in q:\n\t\t\t\t\te.append([nums[i]]+c)\n\t\t\treturn e\n# %%\ns = Solution()\nprint(s.permute(nums = [1,2,3]))", + "status": 1, + "keywords": "数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/45/45_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/45/45_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/45/45_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/46.json b/data_backup/leetcode/46.json new file mode 100644 index 000000000..75c044776 --- /dev/null +++ b/data_backup/leetcode/46.json @@ -0,0 +1,24 @@ +{ + "question_id": 47, + "question_title": "全排列 II", + "difficulty": "中等", + "question_content": "

    给定一个可包含重复数字的序列 nums按任意顺序 返回所有不重复的全排列。

     

    示例 1:

    输入:nums = [1,1,2]
    输出:
    [[1,1,2], [1,2,1], [2,1,1]]

    示例 2:

    输入:nums = [1,2,3]
    输出:
    [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

     

    提示:

      \t
    • 1 <= nums.length <= 8
    • \t
    • -10 <= nums[i] <= 10
    ", + "topic_link": "https://bbs.csdn.net/topics/600470224", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> permuteUnique(vector &nums)\n\t{\n\t\tvector> res;\n\t\tvector used(nums.size());\n\t\tsort(nums.begin(), nums.end());\n\t\tdfs(nums, used, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(vector &nums, vector &used, vector> &res)\n\t{\n\t\tif (stack.size() == nums.size())\n\t\t{\n\t\t\tres.push_back(stack);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = 0; i < nums.size(); i++)\n\t\t\t{\n\t\t\t\tif (!used[i])\n\t\t\t\t{\n\t\t\t\t\tif (i > 0 && !used[i - 1] && nums[i - 1] == nums[i])\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tstack.push_back(nums[i]);\n\t\t\t\t\tused[i] = true;\n\t\t\t\t\tdfs(nums, used, res);\n\t\t\t\t\tstack.pop_back();\n\t\t\t\t\tused[i] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tList> ans = new ArrayList<>();\n\n\tpublic List> permuteUnique(int[] nums) {\n\t\tdfs(nums, 0);\n\t\treturn ans;\n\t}\n\n\tprivate void dfs(int[] nums, int cur) {\n\t\tif (cur == nums.length) {\n\t\t\tList line = new ArrayList<>();\n\t\t\tfor (int i : nums) {\n\t\t\t\tline.add(i);\n\t\t\t}\n\t\t\tans.add(line);\n\t\t} else {\n\t\t\tfor (int i = cur; i < nums.length; i++) {\n\t\t\t\tif (canSwap(nums, cur, i)) {\n\t\t\t\t\tswap(nums, cur, i);\n\t\t\t\t\tdfs(nums, cur + 1);\n\t\t\t\t\tswap(nums, cur, i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate boolean canSwap(int nums[], int begin, int end) {\n\t\tfor (int i = begin; i < end; i++) {\n\t\t\tif (nums[i] == nums[end]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate void swap(int nums[], int i, int j) {\n\t\tint temp = nums[i];\n\t\tnums[i] = nums[j];\n\t\tnums[j] = temp;\n\t}\n}", + "js": "", + "python": "from typing import List\nclass Solution:\n\tdef permuteUnique(self, nums: List[int]) -> List[List[int]]:\n\t\tans = []\n\t\tif len(nums) == 0:\n\t\t\treturn\n\t\tif len(nums) == 1:\n\t\t\treturn [nums]\n\t\tfor index,item in enumerate(nums):\n\t\t\tres = nums[:index]+nums[index+1:]\n\t\t\tfor j in self.permuteUnique(res): \n\t\t\t\tans.append(j+[item])\n\t\trel = []\n\t\tfor i in ans:\n\t\t\tif i not in rel:\n\t\t\t\trel.append(i)\n\t\treturn rel\n# %%\ns = Solution()\nprint(s.permuteUnique(nums = [1,2,3]))", + "status": 1, + "keywords": "数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/46/46_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/46/46_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/46/46_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/47.json b/data_backup/leetcode/47.json new file mode 100644 index 000000000..9777d8338 --- /dev/null +++ b/data_backup/leetcode/47.json @@ -0,0 +1,24 @@ +{ + "question_id": 48, + "question_title": "旋转图像", + "difficulty": "中等", + "question_content": "

    给定一个 × n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。

    你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。

     

    示例 1:

    \"\"
    输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
    输出:
    [[7,4,1],[8,5,2],[9,6,3]]

    示例 2:

    \"\"
    输入:matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
    输出:
    [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]

    示例 3:

    输入:matrix = [[1]]
    输出:
    [[1]]

    示例 4:

    输入:matrix = [[1,2],[3,4]]
    输出:
    [[3,1],[4,2]]

     

    提示:

      \t
    • matrix.length == n
    • \t
    • matrix[i].length == n
    • \t
    • 1 <= n <= 20
    • \t
    • -1000 <= matrix[i][j] <= 1000
    ", + "topic_link": "https://bbs.csdn.net/topics/600470225", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvoid rotate(vector> &matrix)\n\t{\n\t\tint size = matrix.size();\n\t\tfor (int i = 0; i < size / 2; i++)\n\t\t{\n\t\t\tint low = i, high = size - i - 1;\n\t\t\tfor (int j = low; j < high; j++)\n\t\t\t{\n\t\t\t\tint tmp = matrix[i][j];\n\t\t\t\tmatrix[i][j] = matrix[size - 1 - j][i];\n\t\t\t\tmatrix[size - 1 - j][i] = matrix[size - 1 - i][size - 1 - j];\n\t\t\t\tmatrix[size - 1 - i][size - 1 - j] = matrix[j][size - 1 - i];\n\t\t\t\tmatrix[j][size - 1 - i] = tmp;\n\t\t\t}\n\t\t}\n\t}\n};", + "java": "class Solution {\n\n\tpublic void rotate(int[][] matrix) {\n\t\tint len = matrix.length;\n\t\tint le = len - 1;\n\t\tfor (int i = 0; i < len / 2; i++) {\n\t\t\tfor (int j = 0; j < (len + 1) / 2; j++) {\n\t\t\t\tint temp = matrix[i][j];\n\t\t\t\tmatrix[i][j] = matrix[le - j][i];\n\t\t\t\tmatrix[le - j][i] = matrix[le - i][le - j];\n\t\t\t\tmatrix[le - i][le - j] = matrix[j][le - i];\n\t\t\t\tmatrix[j][le - i] = temp;\n\t\t\t}\n\t\t}\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef rotate(self, matrix):\n\t\tif matrix is None or len(matrix) == 1:\n\t\t\treturn\n\t\tls = len(matrix)\n\t\tfor i in range(int(ls / 2)):\n\t\t\tbegin, end = i, ls - 1 - i\n\t\t\tfor k in range(ls - 2 * i - 1):\n\t\t\t\ttemp = matrix[end - k][begin]\n\t\t\t\tmatrix[end - k][begin] = matrix[end][end - k]\n\t\t\t\tmatrix[end][end - k] = matrix[begin + k][end]\n\t\t\t\tmatrix[begin + k][end] = matrix[begin][begin + k]\n\t\t\t\tmatrix[begin][begin + k] = temp\n\t\treturn matrix\nif __name__ == '__main__':\n\ts = Solution()\n\tprint(s.rotate([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]))\n\tprint(s.rotate( [[1,2],[3,4]]))", + "status": 1, + "keywords": "数组,数学,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/47/47_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/47/47_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/47/47_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/48.json b/data_backup/leetcode/48.json new file mode 100644 index 000000000..f3952556b --- /dev/null +++ b/data_backup/leetcode/48.json @@ -0,0 +1,24 @@ +{ + "question_id": 49, + "question_title": "字母异位词分组", + "difficulty": "中等", + "question_content": "

    给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。

    \n

    示例:

    \n
    输入:[eat", "tea", "tan", "ate", "nat", "bat"]
    输出:
    [[ate","eat","tea"],["nat","tan"],["bat"]]
    \n

    说明:

    \n
      \n
    • 所有输入均为小写字母。
    • \n
    • 不考虑答案输出的顺序。
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470799", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> groupAnagrams(vector &strs)\n\t{\n\t\tvector> res;\n\t\tunordered_map> ht;\n\t\tfor (const auto &str : strs)\n\t\t{\n\t\t\tint counts[26] = {0};\n\t\t\tfor (char c : str)\n\t\t\t{\n\t\t\t\tcounts[c - 'a']++;\n\t\t\t}\n\t\t\tstring key;\n\t\t\tfor (int i : counts)\n\t\t\t{\n\t\t\t\tkey.push_back('#');\n\t\t\t\tkey.push_back(i + '0');\n\t\t\t}\n\t\t\tht[key].push_back(str);\n\t\t}\n\t\tfor (const auto &t : ht)\n\t\t{\n\t\t\tres.push_back(t.second);\n\t\t}\n\t\treturn res;\n\t}\n};", + "java": "\nimport java.util.*;\n\npublic class GroupAnagrams {\n\n\tpublic List> groupAnagrams(String[] strs) {\n\t\tHashMap> map = new HashMap<>();\n\t\tfor (String str : strs) {\n\t\t\tchar[] cs = str.toCharArray();\n\t\t\tArrays.sort(cs);\n\n\t\t\tString key = String.valueOf(cs);\n\t\t\tif (!map.containsKey(key)) {\n\t\t\t\tmap.put(key, new ArrayList<>());\n\t\t\t}\n\t\t\tmap.get(key).add(str);\n\t\t}\n\t\treturn new ArrayList(map.values());\n\t}\n\n\tpublic List> groupAnagrams2(String[] strs) {\n\t\tif (strs.length <= 0) {\n\t\t\treturn new ArrayList<>();\n\t\t}\n\t\tHashMap> map = new HashMap<>();\n\t\tfor (String str : strs) {\n\t\t\tchar[] cs = str.toCharArray();\n\t\t\tint[] count = new int[26];\n\t\t\tfor (char c : cs) {\n\t\t\t\t++count[c - 'a'];\n\t\t\t}\n\t\t\tStringBuilder s = new StringBuilder(\"\");\n\t\t\tfor (int num : count) {\n\t\t\t\ts.append(num);\n\t\t\t}\n\n\t\t\tString key = String.valueOf(s);\n\n\t\t\tif (!map.containsKey(key)) {\n\t\t\t\tmap.put(key, new ArrayList<>());\n\t\t\t}\n\t\t\tmap.get(key).add(str);\n\t\t}\n\t\treturn new ArrayList(map.values());\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef groupAnagrams(self, strs):\n\t\tstrs.sort()\n\t\thash = {}\n\t\tfor s in strs:\n\t\t\tkey = self.hash_key(s)\n\t\t\ttry:\n\t\t\t\thash[key].append(s)\n\t\t\texcept KeyError:\n\t\t\t\thash[key] = [s]\n\t\treturn hash.values()\n\tdef hash_key(self, s):\n\t\ttable = [0] * 26\n\t\tfor ch in s:\n\t\t\tindex = ord(ch) - ord('a')\n\t\t\ttable[index] += 1\n\t\treturn str(table)\n# %%\ns = Solution()\nprint(s.groupAnagrams(strs = [\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]))", + "status": 1, + "keywords": "哈希表,字符串,排序", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/48/48_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/48/48_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/48/48_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/49.json b/data_backup/leetcode/49.json new file mode 100644 index 000000000..5784d584f --- /dev/null +++ b/data_backup/leetcode/49.json @@ -0,0 +1,24 @@ +{ + "question_id": 50, + "question_title": "Pow(x, n)", + "difficulty": "中等", + "question_content": "

    实现 pow(x, n) ,即计算 x 的 n 次幂函数(即,xn)。

     

    示例 1:

    输入:x = 2.00000, n = 10
    输出:
    1024.00000

    示例 2:

    输入:x = 2.10000, n = 3
    输出:
    9.26100

    示例 3:

    输入:x = 2.00000, n = -2
    输出:
    0.25000
    解释:
    2-2 = 1/22 = 1/4 = 0.25

     

    提示:

      \t
    • -100.0 < x < 100.0
    • \t
    • -231 <= n <= 231-1
    • \t
    • -104 <= xn <= 104
    ", + "topic_link": "https://bbs.csdn.net/topics/600471013", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tdouble myPow(double x, int n)\n\t{\n\t\tif (n == INT_MIN)\n\t\t{\n\t\t\tdouble t = dfs(x, -(n / 2));\n\t\t\treturn 1 / t * 1 / t;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn n < 0 ? 1 / dfs(x, -n) : dfs(x, n);\n\t\t}\n\t}\nprivate:\n\tdouble dfs(double x, int n)\n\t{\n\t\tif (n == 0)\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\telse if (n == 1)\n\t\t{\n\t\t\treturn x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdouble t = dfs(x, n / 2);\n\t\t\treturn (n % 2) ? (x * t * t) : (t * t);\n\t\t}\n\t}\n};", + "java": "public class Solution {\n\tpublic double myPow(double x, int n) {\n\t\tif (n < 0) {\n\n\t\t\treturn 1 / pow(x, -n);\n\t\t} else {\n\n\t\t\treturn pow(x, n);\n\t\t}\n\t}\n\n\tprivate double pow(double x, int n) {\n\n\t\tif (n == 0) {\n\t\t\treturn 1.0;\n\t\t}\n\t\tif (n == 1) {\n\t\t\treturn x;\n\t\t}\n\t\tdouble val = pow(x, n / 2);\n\n\t\tif (n % 2 == 0) {\n\t\t\treturn val * val;\n\t\t} else {\n\t\t\treturn val * val * x;\n\t\t}\n\t}\n}\n", + "js": "", + "python": "class Solution:\n\tdef myPow(self, x, n):\n\t\tif n == 0:\n\t\t\treturn 1\n\t\tres ,curr = 1, abs(n)\n\t\twhile curr > 0:\n\t\t\tif curr & 1 == 1:\n\t\t\t\tres *= x\n\t\t\tcurr >>= 1\n\t\t\tx *= x\n\t\tif n < 0:\n\t\t\treturn 1 / res\n\t\treturn res\n# %%\ns = Solution()\nprint(s.myPow(x = 2.00000, n = 10))", + "status": 1, + "keywords": "递归,数学", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/49/49_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/49/49_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/49/49_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/5.json b/data_backup/leetcode/5.json new file mode 100644 index 000000000..e31fde967 --- /dev/null +++ b/data_backup/leetcode/5.json @@ -0,0 +1,24 @@ +{ + "question_id": 6, + "question_title": "Z 字形变换", + "difficulty": "中等", + "question_content": "
    \n

    将一个给定字符串 s 根据给定的行数 numRows ,以从上往下、从左到右进行 Z 字形排列。

    \n\n

    比如输入字符串为 \"PAYPALISHIRING\" 行数为 3 时,排列如下:

    \n\n
    \n    P   A   H   N\n    A P L S I I G\n    Y   I   R
    \n\n

    之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:\"PAHNAPLSIIGYIR\"

    \n\n

    请你实现这个将字符串进行指定行数变换的函数:

    \n\n
    string convert(string s, int numRows);
    \n\n

     

    \n\n

    示例 1:

    \n\n
    输入:s = \"PAYPALISHIRING\", numRows = 3\n输出:\"PAHNAPLSIIGYIR\"\n
    \n 示例 2:\n\n
    输入:s = \"PAYPALISHIRING\", numRows = 4\n输出:\"PINALSIGYAHRPI\"\n解释:\nP     I    N\nA   L S  I G\nY A   H R\nP     I\n
    \n\n

    示例 3:

    \n\n
    输入:s = \"A\", numRows = 1\n输出:\"A\"\n
    \n\n

     

    \n\n

    提示:

    \n\n
      \n
    • 1 <= s.length <= 1000
    • \n
    • s 由英文字母(小写和大写)、',''.' 组成
    • \n
    • 1 <= numRows <= 1000
    • \n
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600469917", + "cpp": "class Solution\n{\npublic:\n\tstring convert(string s, int numRows)\n\t{\n\t\tif (numRows == 1)\n\t\t\treturn s;\n\t\tint len = s.size();\n\t\tif (len <= numRows)\n\t\t\treturn s;\n\t\tint cycle_len = 2 * numRows - 2;\n\t\tint full_cycles = len / cycle_len;\n\t\tint left = len % cycle_len;\n\t\tstring r;\n\t\tint i;\n\t\tfor (i = 0; i < full_cycles; ++i)\n\t\t{\n\t\t\tr += s[i * cycle_len];\n\t\t}\n\t\tif (left)\n\t\t\tr += s[i * cycle_len];\n\t\tfor (i = 0; i < numRows - 2; ++i)\n\t\t{\n\t\t\tint j;\n\t\t\tfor (j = 0; j < full_cycles; ++j)\n\t\t\t{\n\t\t\t\tr += s[j * cycle_len + i + 1];\n\t\t\t\tr += s[j * cycle_len + i + 1 + cycle_len - 2 * (i + 1)];\n\t\t\t}\n\t\t\tif (left)\n\t\t\t{\n\t\t\t\tif (j * cycle_len + i + 1 < len)\n\t\t\t\t\tr += s[j * cycle_len + i + 1];\n\t\t\t\tif (j * cycle_len + i + 1 + cycle_len - 2 * (i + 1) < len)\n\t\t\t\t\tr += s[j * cycle_len + i + 1 + cycle_len - 2 * (i + 1)];\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < full_cycles; ++i)\n\t\t\tr += s[i * cycle_len + numRows - 1];\n\t\tif (left >= numRows)\n\t\t\tr += s[i * cycle_len + numRows - 1];\n\t\treturn r;\n\t}\n};", + "java": "class Solution {\n\tpublic String convert(String s, int numRows) {\n\t\tif (numRows == 1)\n\t\t\treturn s;\n\t\tint len = s.length();\n\t\tif (len <= numRows)\n\t\t\treturn s;\n\t\tint cycle_len = 2 * numRows - 2;\n\t\tint full_cycles = len / cycle_len;\n\t\tint left = len % cycle_len;\n\t\tStringBuilder r = new StringBuilder();\n\t\tint i;\n\t\tfor (i = 0; i < full_cycles; ++i) {\n\t\t\tr.append(s.charAt(i * cycle_len));\n\t\t}\n\t\tif (left > 0) {\n\t\t\tr.append(s.charAt(i * cycle_len));\n\t\t}\n\t\tfor (i = 0; i < numRows - 2; ++i) {\n\t\t\tint j;\n\t\t\tfor (j = 0; j < full_cycles; ++j) {\n\t\t\t\tr.append(s.charAt(j * cycle_len + i + 1));\n\t\t\t\tr.append(s.charAt(j * cycle_len + i + 1 + cycle_len - 2 * (i + 1)));\n\t\t\t}\n\t\t\tif (left > 0) {\n\t\t\t\tif (j * cycle_len + i + 1 < len)\n\t\t\t\t\tr.append(s.charAt(j * cycle_len + i + 1));\n\t\t\t\tif (j * cycle_len + i + 1 + cycle_len - 2 * (i + 1) < len)\n\t\t\t\t\tr.append(s.charAt(j * cycle_len + i + 1 + cycle_len - 2 * (i + 1)));\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < full_cycles; ++i)\n\t\t\tr.append(s.charAt(i * cycle_len + numRows - 1));\n\t\tif (left >= numRows)\n\t\t\tr.append(s.charAt(i * cycle_len + numRows - 1));\n\t\treturn r.toString();\n\t}\n}", + "js": "/**\n * @param {string} s\n * @param {number} numRows\n * @return {string}\n */\nvar convert = function(s, numRows) {\n let n = s.length;\n \n let N = numRows;\n\n if(s.length===1){\n return s;\n }\n if(N===1){\n return s;\n }\n \n let S = N-2;\n let C = 2*N-2;\n let R = Math.floor(n/C);\n let RS = n%(C);\n let CE = n-R*C; \n \n let RR = (RS<=N) ? 1 : 1+(RS-N);\n let RX = R*(N-1) + RR ;\n\n const output=[];\n\n for(let i=0;i0&&i\\n',c[0], '\\n', c[2], '\\n', v);\n console.assert(v===c[2]);\n}\n\n// P I N\n// A L S I G \n// Y A H R\n// P I\n\n\n\n\n\n", + "python": "import math\nclass Solution:\n\tdef convert(self, s: str, numRows: int) -> str:\n\t\tn = len(s)\n\t\tN = numRows\n\t\tif n == 1 or N == 1:\n\t\t\treturn s\n\t\tS = N-2\n\t\tC = 2*N-2\n\t\tR = int(math.floor(n/C))\n\t\tRS = n % (C)\n\t\tCE = n-R*C\n\t\tRR = 1 if (RS <= N) else 1+(RS-N)\n\t\tRX = R*(N-1) + RR\n\t\toutput = []\n\t\ti = 0\n\t\twhile i < N:\n\t\t\tj = 0\n\t\t\tk = (N-1-i)\n\t\t\twhile j < RX:\n\t\t\t\tr = int(math.floor(j/(N-1)))\n\t\t\t\trs = j % (N-1)\n\t\t\t\toffset = i if rs == 0 else N+rs-1\n\t\t\t\tindex = r*C+offset\n\t\t\t\tif index < len(s):\n\t\t\t\t\toutput.append(s[index])\n\t\t\t\tif i > 0 and i < N-1:\n\t\t\t\t\tr = int(math.floor(k/(N-1)))\n\t\t\t\t\trs = k % (N-1)\n\t\t\t\t\toffset = i if rs == 0 else N+rs-1\n\t\t\t\t\tindex = r*C+offset\n\t\t\t\t\tif index < len(s):\n\t\t\t\t\t\toutput.append(s[index])\n\t\t\t\tj += (N-1)\n\t\t\t\tk += (N-1)\n\t\t\ti += 1\n\t\treturn ''.join(output)\n# %%\ns = Solution()\nprint(s.convert('PAYPALISHIRING', 3))", + "status": 1, + "keywords": "字符串", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/5/5_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/5/5_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/5/5_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/50.json b/data_backup/leetcode/50.json new file mode 100644 index 000000000..d116b7304 --- /dev/null +++ b/data_backup/leetcode/50.json @@ -0,0 +1,24 @@ +{ + "question_id": 51, + "question_title": "N 皇后", + "difficulty": "困难", + "question_content": "

    n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。

    给你一个整数 n ,返回所有不同的 n 皇后问题 的解决方案。

    每一种解法包含一个不同的 n 皇后问题 的棋子放置方案,该方案中 'Q''.' 分别代表了皇后和空位。

     

    示例 1:

    \"\"
    输入:n = 4
    输出:
    [[\".Q..\",\"...Q\",\"Q...\",\"..Q.\"],[\"..Q.\",\"Q...\",\"...Q\",\".Q..\"]]
    解释:
    如上图所示,4 皇后问题存在两个不同的解法。

    示例 2:

    输入:n = 1
    输出:
    [[\"Q\"]]

     

    提示:

      \t
    • 1 <= n <= 9
    • \t
    • 皇后彼此不能相互攻击,也就是说:任何两个皇后都不能处于同一条横行、纵行或斜线上。
    ", + "topic_link": "https://bbs.csdn.net/topics/600470831", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> solveNQueens(int n)\n\t{\n\t\tvector> res;\n\t\tvector stack(n);\n\t\tvector solution(n, string(n, '.'));\n\t\tdfs(n, 0, stack, solution, res);\n\t\treturn res;\n\t}\nprivate:\n\tvoid dfs(int n, int row, vector &stack, vector &solution, vector> &res)\n\t{\n\t\tif (row == n)\n\t\t{\n\t\t\tres.push_back(solution);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\tif (row == 0 || !conflict(stack, row, i))\n\t\t\t\t{\n\t\t\t\t\tsolution[row][i] = 'Q';\n\t\t\t\t\tstack[row] = i;\n\t\t\t\t\tdfs(n, row + 1, stack, solution, res);\n\t\t\t\t\tsolution[row][i] = '.';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tbool conflict(vector &stack, int row, int col)\n\t{\n\t\tfor (int i = 0; i < row; i++)\n\t\t{\n\t\t\tif (col == stack[i] || abs(row - i) == abs(col - stack[i]))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}", + "java": "import java.util.List;\nimport java.util.ArrayList;\npublic class Solution {\n\tpublic List> solveNQueens(int n) {\n\t\tList> res = new ArrayList>();\n\t\tint[] queenList = new int[n];\n\t\tplaceQueen(queenList, 0, n, res);\n\t\treturn res;\n\t}\n\tprivate void placeQueen(int[] queenList, int row, int n, List> res) {\n\t\tif (row == n) {\n\t\t\tArrayList list = new ArrayList();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tString str = \"\";\n\t\t\t\tfor (int col = 0; col < n; col++) {\n\t\t\t\t\tif (queenList[i] == col) {\n\t\t\t\t\t\tstr += \"Q\";\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstr += \".\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlist.add(str);\n\t\t\t}\n\t\t\tres.add(list);\n\t\t}\n\t\tfor (int col = 0; col < n; col++) {\n\t\t\tif (isValid(queenList, row, col)) {\n\t\t\t\tqueenList[row] = col;\n\t\t\t\tplaceQueen(queenList, row + 1, n, res);\n\t\t\t}\n\t\t}\n\t}\n\tprivate boolean isValid(int[] queenList, int row, int col) {\n\t\tfor (int i = 0; i < row; i++) {\n\t\t\tint pos = queenList[i];\n\t\t\tif (pos == col) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (pos + row - i == col) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (pos - row + i == col) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef solveNQueens(self, n):\n\t\tif n == 0:\n\t\t\treturn 0\n\t\tres = []\n\t\tboard = [['.'] * n for t in range(n)]\n\t\tself.do_solveNQueens(res, board, n)\n\t\treturn res\n\tdef do_solveNQueens(self, res, board, num):\n\t\tif num == 0:\n\t\t\tres.append([''.join(t) for t in board])\n\t\t\treturn\n\t\tls = len(board)\n\t\tpos = ls - num\n\t\tcheck = [True] * ls\n\t\tfor i in range(pos):\n\t\t\tfor j in range(ls):\n\t\t\t\tif board[i][j] == 'Q':\n\t\t\t\t\tcheck[j] = False\n\t\t\t\t\tstep = pos - i\n\t\t\t\t\tif j + step < ls:\n\t\t\t\t\t\tcheck[j + step] = False\n\t\t\t\t\tif j - step >= 0:\n\t\t\t\t\t\tcheck[j - step] = False\n\t\t\t\t\tbreak\n\t\tfor j in range(ls):\n\t\t\tif check[j]:\n\t\t\t\tboard[pos][j] = 'Q'\n\t\t\t\tself.do_solveNQueens(res, board, num - 1)\n\t\t\t\tboard[pos][j] = '.'\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.solveNQueens(4))", + "status": 1, + "keywords": "数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104324976" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/50/50_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/50/50_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/50/50_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/51.json b/data_backup/leetcode/51.json new file mode 100644 index 000000000..4a28b8ed0 --- /dev/null +++ b/data_backup/leetcode/51.json @@ -0,0 +1,24 @@ +{ + "question_id": 52, + "question_title": "N皇后 II", + "difficulty": "困难", + "question_content": "
    \n

    n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。

    \n\n

    给你一个整数 n ,返回 n 皇后问题 不同的解决方案的数量。

    \n\n

     

    \n\n
    \n
    \n

    示例 1:

    \n \"\"\n
    输入:n = 4\n输出:2\n解释:如上图所示,4 皇后问题存在两个不同的解法。\n    
    \n\n

    示例 2:

    \n\n
    输入:n = 1\n输出:1\n    
    \n\n

     

    \n\n

    提示:

    \n\n
      \n
    • 1 <= n <= 9
    • \n
    • 皇后彼此不能相互攻击,也就是说:任何两个皇后都不能处于同一条横行、纵行或斜线上。
    • \n
    \n
    \n
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470922", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint totalNQueens(int n)\n\t{\n\t\tvector stack(n);\n\t\treturn dfs(n, 0, stack);\n\t}\nprivate:\n\tint dfs(int n, int row, vector &stack)\n\t{\n\t\tint count = 0;\n\t\tif (row == n)\n\t\t{\n\t\t\treturn count + 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\tif (row == 0 || !conflict(stack, row, i))\n\t\t\t\t{\n\t\t\t\t\tstack[row] = i;\n\t\t\t\t\tcount += dfs(n, row + 1, stack);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn count;\n\t\t}\n\t}\n\tbool conflict(vector &stack, int row, int col)\n\t{\n\t\tfor (int i = 0; i < row; i++)\n\t\t{\n\t\t\tif (col == stack[i] || abs(row - i) == abs(col - stack[i]))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}", + "java": "class Solution {\n\tprivate boolean col[];\n\tprivate boolean dia1[];\n\tprivate boolean dia2[];\n\tpublic int totalNQueens(int n) {\n\t\tcol = new boolean[n];\n\t\tdia1 = new boolean[2 * n - 1];\n\t\tdia2 = new boolean[2 * n - 1];\n\t\treturn putQueen(n, 0);\n\t}\n\tprivate int putQueen(int n, int index) {\n\t\tint res = 0;\n\t\tif (index == n) {\n\t\t\treturn 1;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!col[i] && !dia1[i - index + n - 1] && !dia2[i + index]) {\n\t\t\t\tcol[i] = true;\n\t\t\t\tdia1[i - index + n - 1] = true;\n\t\t\t\tdia2[i + index] = true;\n\t\t\t\tres += putQueen(n, index + 1);\n\t\t\t\tcol[i] = false;\n\t\t\t\tdia1[i - index + n - 1] = false;\n\t\t\t\tdia2[i + index] = false;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef __init__(self):\n\t\tself.count = 0\n\tdef totalNQueens(self, n):\n\t\tself.dfs(0, n, 0, 0, 0)\n\t\treturn self.count\n\tdef dfs(self, row, n, column, diag, antiDiag):\n\t\tif row == n:\n\t\t\tself.count += 1\n\t\t\treturn\n\t\tfor index in range(n):\n\t\t\tisColSafe = (1 << index) & column == 0\n\t\t\tisDigSafe = (1 << (n - 1 + row - index)) & diag == 0\n\t\t\tisAntiDiagSafe = (1 << (row + index)) & antiDiag == 0\n\t\t\tif isAntiDiagSafe and isColSafe and isDigSafe:\n\t\t\t\tself.dfs(row + 1, n, (1 << index) | column,\n\t\t\t\t\t\t (1 << (n - 1 + row - index)) | diag,\n\t\t\t\t\t\t (1 << (row + index)) | antiDiag)\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.totalNQueens(4))", + "status": 1, + "keywords": "回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104325309" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/51/51_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/51/51_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/51/51_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/52.json b/data_backup/leetcode/52.json new file mode 100644 index 000000000..bdcbe68c5 --- /dev/null +++ b/data_backup/leetcode/52.json @@ -0,0 +1,24 @@ +{ + "question_id": 53, + "question_title": "最大子序和", + "difficulty": "简单", + "question_content": "

    给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。

     

    示例 1:

    输入:nums = [-2,1,-3,4,-1,2,1,-5,4]
    输出:
    6
    解释:
    连续子数组 [4,-1,2,1] 的和最大,为 6 。

    示例 2:

    输入:nums = [1]
    输出:
    1

    示例 3:

    输入:nums = [0]
    输出:
    0

    示例 4:

    输入:nums = [-1]
    输出:
    -1

    示例 5:

    输入:nums = [-100000]
    输出:
    -100000

     

    提示:

      \t
    • 1 <= nums.length <= 3 * 104
    • \t
    • -105 <= nums[i] <= 105

     

    进阶:如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的 分治法 求解。

    ", + "topic_link": "https://bbs.csdn.net/topics/600469821", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint maxSubArray(vector &nums)\n\t{\n\t\tint sum = 0, max_sum = INT_MIN;\n\t\tfor (int i = 0; i < nums.size(); i++)\n\t\t{\n\t\t\tif (sum < 0)\n\t\t\t{\n\t\t\t\tsum = nums[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsum += nums[i];\n\t\t\t}\n\t\t\tmax_sum = max(sum, max_sum);\n\t\t}\n\t\treturn max_sum;\n\t}\n};", + "java": "class Solution {\n\tpublic int maxSubArray(int[] nums) {\n\t\tint maxSum = nums[0];\n\t\tint curSum = 0;\n\n\t\tfor (int n : nums) {\n\t\t\tcurSum += n;\n\t\t\tif (curSum > maxSum) {\n\t\t\t\tmaxSum = curSum;\n\t\t\t}\n\t\t\tif (curSum < 0) {\n\t\t\t\tcurSum = 0;\n\t\t\t}\n\t\t}\n\n\t\treturn maxSum;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef maxSubArray(self, nums):\n\t\tmaxEndingHere = maxSofFar = nums[0]\n\t\tfor i in range(1, len(nums)):\n\t\t\tmaxEndingHere = max(maxEndingHere + nums[i], nums[i])\n\t\t\tmaxSofFar = max(maxEndingHere, maxSofFar)\n\t\treturn maxSofFar\n# %%\ns = Solution()\nprint(s.maxSubArray(nums = [-2,1,-3,4,-1,2,1,-5,4]))", + "status": 1, + "keywords": "数组,分治,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/52/52_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/52/52_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/52/52_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/53.json b/data_backup/leetcode/53.json new file mode 100644 index 000000000..1caf4e828 --- /dev/null +++ b/data_backup/leetcode/53.json @@ -0,0 +1,24 @@ +{ + "question_id": 54, + "question_title": "螺旋矩阵", + "difficulty": "中等", + "question_content": "

    给你一个 mn 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。

     

    示例 1:

    \"\"
    输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
    输出:
    [1,2,3,6,9,8,7,4,5]

    示例 2:

    \"\"
    输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
    输出:
    [1,2,3,4,8,12,11,10,9,5,6,7]

     

    提示:

      \t
    • m == matrix.length
    • \t
    • n == matrix[i].length
    • \t
    • 1 <= m, n <= 10
    • \t
    • -100 <= matrix[i][j] <= 100
    ", + "topic_link": "https://bbs.csdn.net/topics/600470121", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector spiralOrder(vector> &matrix)\n\t{\n\t\tvector res;\n\t\tint hor_top = 0;\n\t\tint hor_bottom = matrix.size() - 1;\n\t\tint ver_left = 0;\n\t\tint ver_right = matrix[0].size() - 1;\n\t\tint direction = 0;\n\t\twhile (hor_top <= hor_bottom && ver_left <= ver_right)\n\t\t{\n\t\t\tswitch (direction)\n\t\t\t{\n\t\t\tcase 0:\n\t\t\t\tfor (int i = ver_left; i <= ver_right; i++)\n\t\t\t\t{\n\t\t\t\t\tres.push_back(matrix[hor_top][i]);\n\t\t\t\t}\n\t\t\t\thor_top++;\n\t\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\t\tfor (int i = hor_top; i <= hor_bottom; i++)\n\t\t\t\t{\n\t\t\t\t\tres.push_back(matrix[i][ver_right]);\n\t\t\t\t}\n\t\t\t\tver_right--;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tfor (int i = ver_right; i >= ver_left; i--)\n\t\t\t\t{\n\t\t\t\t\tres.push_back(matrix[hor_bottom][i]);\n\t\t\t\t}\n\t\t\t\thor_bottom--;\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tfor (int i = hor_bottom; i >= hor_top; i--)\n\t\t\t\t{\n\t\t\t\t\tres.push_back(matrix[i][ver_left]);\n\t\t\t\t}\n\t\t\t\tver_left++;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdirection++;\n\t\t\tdirection %= 4;\n\t\t}\n\t\treturn res;\n\t}\n};", + "java": "class Solution {\n\tpublic List spiralOrder(int[][] matrix) {\n\t\tList res = new ArrayList();\n\t\tif (matrix.length == 0 || (matrix.length == 1 && matrix[0].length == 0))\n\t\t\treturn res;\n\t\tint left = 0;\n\t\tint right = matrix[0].length - 1;\n\t\tint top = 0;\n\t\tint bottom = matrix.length - 1;\n\t\tint num = (right + 1) * (bottom + 1);\n\t\twhile (num > 0) {\n\t\t\tfor (int j = left; j <= right; j++) {\n\t\t\t\tres.add(matrix[top][j]);\n\t\t\t\tnum--;\n\t\t\t}\n\t\t\tif (num <= 0)\n\t\t\t\tbreak;\n\t\t\ttop++;\n\t\t\tfor (int i = top; i <= bottom; i++) {\n\t\t\t\tres.add(matrix[i][right]);\n\t\t\t\tnum--;\n\t\t\t}\n\t\t\tif (num <= 0)\n\t\t\t\tbreak;\n\t\t\tright--;\n\t\t\tfor (int j = right; j >= left; j--) {\n\t\t\t\tres.add(matrix[bottom][j]);\n\t\t\t\tnum--;\n\t\t\t}\n\t\t\tif (num <= 0)\n\t\t\t\tbreak;\n\t\t\tbottom--;\n\t\t\tfor (int i = bottom; i >= top; i--) {\n\t\t\t\tres.add(matrix[i][left]);\n\t\t\t\tnum--;\n\t\t\t}\n\t\t\tif (num <= 0)\n\t\t\t\tbreak;\n\t\t\tleft++;\n\t\t}\n\t\treturn res;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef spiralOrder(self, matrix):\n\t\t\"\"\"\n\t\t:type matrix: List[List[int]]\n\t\t:rtype: List[int]\n\t\t\"\"\"\n\t\tif matrix is None or len(matrix) == 0:\n\t\t\treturn matrix\n\t\tm, n = len(matrix), len(matrix[0])\n\t\treturn self.get_spiralOrder(matrix, 0, m - 1, 0, n - 1)\n\tdef get_spiralOrder(self, matrix, r_start, r_end, c_start, c_end):\n\t\tif r_start > r_end or c_start > c_end:\n\t\t\treturn []\n\t\telif r_start == r_end:\n\t\t\treturn matrix[r_start][c_start:c_end + 1]\n\t\telif c_start == c_end:\n\t\t\treturn [matrix[j][c_end] for j in range(r_start, r_end + 1)]\n\t\tcurr = matrix[r_start][c_start:c_end + 1] + [matrix[j][c_end] for j in range(r_start + 1, r_end)] +\\\n\t\t\t\tmatrix[r_end][c_start:c_end + 1][::-1] +\\\n\t\t\t\t[matrix[j][c_start] for j in reversed(range(r_start + 1, r_end))]\n\t\tres = curr + self.get_spiralOrder(matrix, r_start + 1, r_end - 1, c_start + 1, c_end - 1)\n\t\treturn res\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.spiralOrder([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]))", + "status": 1, + "keywords": "数组,矩阵,模拟", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/53/53_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/53/53_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/53/53_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/54.json b/data_backup/leetcode/54.json new file mode 100644 index 000000000..e819b206b --- /dev/null +++ b/data_backup/leetcode/54.json @@ -0,0 +1,24 @@ +{ + "question_id": 55, + "question_title": "跳跃游戏", + "difficulty": "中等", + "question_content": "

    给定一个非负整数数组 nums ,你最初位于数组的 第一个下标

    数组中的每个元素代表你在该位置可以跳跃的最大长度。

    判断你是否能够到达最后一个下标。

     

    示例 1:

    输入:nums = [2,3,1,1,4]
    输出:
    true
    解释:
    可以先跳 1 步,从下标 0 到达下标 1, 然后再从下标 1 跳 3 步到达最后一个下标。

    示例 2:

    输入:nums = [3,2,1,0,4]
    输出:
    false
    解释:
    无论怎样,总会到达下标为 3 的位置。但该下标的最大跳跃长度是 0 , 所以永远不可能到达最后一个下标。

     

    提示:

      \t
    • 1 <= nums.length <= 3 * 104
    • \t
    • 0 <= nums[i] <= 105
    ", + "topic_link": "https://bbs.csdn.net/topics/600470122", + "cpp": "#include \n#include \n#include \nstatic inline int max(int a, int b)\n{\n\treturn a > b ? a : b;\n}\nstatic bool canJump(int *nums, int numsSize)\n{\n\tint i, pos = 0;\n\tfor (i = 0; i < numsSize - 1; i++)\n\t{\n\t\tif (pos < i || pos >= numsSize - 1)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tpos = max(i + nums[i], pos);\n\t}\n\treturn pos >= numsSize - 1;\n}\nint main(int argc, char **argv)\n{\n\tint i, count = argc - 1;\n\tint *nums = malloc(count * sizeof(int));\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tnums[i] = atoi(argv[i + 1]);\n\t}\n\tprintf(\"%s\\n\", canJump(nums, count) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean canJump(int[] nums) {\n\t\tboolean can = true;\n\t\tif (nums.length < 2) {\n\t\t\treturn can;\n\t\t}\n\t\tint n = nums.length;\n\t\tint stride = 1;\n\t\tfor (int i = n - 2; i >= 0; i--) {\n\t\t\tif (nums[i] < stride) {\n\t\t\t\tstride++;\n\t\t\t\tcan = false;\n\t\t\t} else {\n\t\t\t\tcan = true;\n\t\t\t\tstride = 1;\n\t\t\t}\n\t\t}\n\t\treturn can;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef canJump(self, nums):\n\t\t\"\"\"\n\t\t:type nums: List[int]\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\tlength = len(nums)\n\t\tbegin = length - 1\n\t\tfor i in reversed(range(length - 1)):\n\t\t\tif i + nums[i] >= begin:\n\t\t\t\tbegin = i\n\t\treturn not begin\n# %%\ns = Solution()\nprint(s.canJump(nums = [2,3,1,1,4]))", + "status": 1, + "keywords": "贪心,数组,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/54/54_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/54/54_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/54/54_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/55.json b/data_backup/leetcode/55.json new file mode 100644 index 000000000..9edeff2c3 --- /dev/null +++ b/data_backup/leetcode/55.json @@ -0,0 +1,24 @@ +{ + "question_id": 56, + "question_title": "合并区间", + "difficulty": "中等", + "question_content": "

    以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i] = [starti, endi] 。请你合并所有重叠的区间,并返回一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间。

     

    示例 1:

    输入:intervals = [[1,3],[2,6],[8,10],[15,18]]
    输出:
    [[1,6],[8,10],[15,18]]
    解释:
    区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6].

    示例 2:

    输入:intervals = [[1,4],[4,5]]
    输出:
    [[1,5]]
    解释:
    区间 [1,4] 和 [4,5] 可被视为重叠区间。

     

    提示:

      \t
    • 1 <= intervals.length <= 104
    • \t
    • intervals[i].length == 2
    • \t
    • 0 <= starti <= endi <= 104
    ", + "topic_link": "https://bbs.csdn.net/topics/600471018", + "cpp": "#include \n#include \n#include \nstatic int compare(const void *a, const void *b)\n{\n\treturn ((int *)a)[0] - ((int *)b)[0];\n}\nint **merge(int **intervals, int intervalsSize, int *intervalsColSize, int *returnSize, int **returnColumnSizes)\n{\n\tif (intervalsSize == 0)\n\t{\n\t\t*returnSize = 0;\n\t\treturn intervals;\n\t}\n\tint i, len = 0;\n\tint *tmp = malloc(intervalsSize * 2 * sizeof(int));\n\tfor (i = 0; i < intervalsSize; i++)\n\t{\n\t\ttmp[i * 2] = intervals[i][0];\n\t\ttmp[i * 2 + 1] = intervals[i][1];\n\t}\n\tqsort(tmp, intervalsSize, 2 * sizeof(int), compare);\n\tintervals[0][0] = tmp[0];\n\tintervals[0][1] = tmp[1];\n\tfor (i = 1; i < intervalsSize; i++)\n\t{\n\t\tif (tmp[i * 2] > intervals[len][1])\n\t\t{\n\t\t\tlen++;\n\t\t\tintervals[len][0] = tmp[i * 2];\n\t\t\tintervals[len][1] = tmp[i * 2 + 1];\n\t\t}\n\t\telse if (tmp[i * 2 + 1] > intervals[len][1])\n\t\t{\n\t\t\tintervals[len][1] = tmp[i * 2 + 1];\n\t\t}\n\t}\n\tlen += 1;\n\t*returnSize = len;\n\t*returnColumnSizes = malloc(len * sizeof(int));\n\tfor (i = 0; i < len; i++)\n\t{\n\t\t(*returnColumnSizes)[i] = 2;\n\t}\n\treturn intervals;\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 1 || argc % 2 == 0)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test s0 e0 s1 e1...\");\n\t\texit(-1);\n\t}\n\tint i, count = 0;\n\tint *sizes = malloc((argc - 1) / 2 * sizeof(int));\n\tint **intervals = malloc((argc - 1) / 2 * sizeof(int *));\n\tfor (i = 0; i < (argc - 1) / 2; i++)\n\t{\n\t\tsizes[i] = 2;\n\t\tintervals[i] = malloc(2 * sizeof(int));\n\t\tintervals[i][0] = atoi(argv[i * 2 + 1]);\n\t\tintervals[i][1] = atoi(argv[i * 2 + 2]);\n\t}\n\tint *col_sizes;\n\tint **results = merge(intervals, (argc - 1) / 2, sizes, &count, &col_sizes);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tprintf(\"[%d,%d]\\n\", results[i][0], results[i][1]);\n\t}\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int[][] merge(int[][] intervals) {\n\t\tList res = new ArrayList<>();\n\t\tif (intervals == null) {\n\t\t\treturn res.toArray(new int[0][]);\n\t\t}\n\t\tArrays.sort(intervals, (a, b) -> a[0] - b[0]);\n\t\tint i = 0;\n\t\tint left = 0;\n\t\tint right = 0;\n\t\twhile (i < intervals.length) {\n\t\t\tleft = intervals[i][0];\n\t\t\tright = intervals[i][1];\n\t\t\twhile (i < intervals.length - 1 && right >= intervals[i + 1][0]) {\n\t\t\t\ti++;\n\t\t\t\tright = Math.max(right, intervals[i][1]);\n\t\t\t}\n\t\t\tres.add(new int[] { left, right });\n\t\t\ti++;\n\t\t}\n\t\treturn res.toArray(new int[0][]);\n\t}\n}\n", + "js": "", + "python": "class Interval(object):\n\tdef __init__(self, s=0, e=0):\n\t\tself.start = s\n\t\tself.end = e\nclass Solution(object):\n\tdef list2interval(self, list_interval):\n\t\tret = []\n\t\tfor i in list_interval:\n\t\t\tinterval = Interval(i[0], i[1])\n\t\t\tret.append(interval)\n\t\treturn ret\n\tdef interval2list(self, interval):\n\t\tret = []\n\t\tx = [0,0]\n\t\tfor i in interval:\n\t\t\tx[0] = i.start\n\t\t\tx[1] = i.end\n\t\t\tret.append(x)\n\t\t\tx = [0,0]\n\t\treturn ret\n\tdef merge(self, intervals):\n\t\t\"\"\"\n\t\t:type intervals: List[Interval]\n\t\t:rtype: List[Interval]\n\t\t\"\"\"\n\t\tif intervals is None:\n\t\t\treturn\n\t\tls = len(intervals)\n\t\tif ls <= 1:\n\t\t\treturn intervals\n\t\tintervals = self.list2interval(intervals)\t\t\n\t\tintervals.sort(key=lambda x: x.start)\n\t\tpos = 0\n\t\twhile pos < len(intervals) - 1:\n\t\t\tif intervals[pos].end >= intervals[pos + 1].start:\n\t\t\t\tnext = intervals.pop(pos + 1)\n\t\t\t\tif next.end > intervals[pos].end:\n\t\t\t\t\tintervals[pos].end = next.end\n\t\t\telse:\n\t\t\t\tpos += 1\n\t\tintervals = self.interval2list(intervals)\n\t\treturn intervals\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.merge(intervals = [[1,4],[4,5]]))", + "status": 1, + "keywords": "数组,排序", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/55/55_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/55/55_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/55/55_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/56.json b/data_backup/leetcode/56.json new file mode 100644 index 000000000..e54066890 --- /dev/null +++ b/data_backup/leetcode/56.json @@ -0,0 +1,24 @@ +{ + "question_id": 57, + "question_title": "插入区间", + "difficulty": "中等", + "question_content": "

    给你一个 无重叠的按照区间起始端点排序的区间列表。

    \n

    在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。

    \n

     

    \n

    示例 1:

    \n
    输入:intervals = [[1,3],[6,9]], newInterval = [2,5]
    输出:
    [[1,5],[6,9]]
    \n

    示例 2:

    \n
    输入:intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
    输出:
    [[1,2],[3,10],[12,16]]
    解释:
    这是因为新的区间 [4,8] 与 [3,5],[6,7],[8,10] 重叠。
    \n

    示例 3:

    \n
    输入:intervals = [], newInterval = [5,7]
    输出:
    [[5,7]]
    \n

    示例 4:

    \n
    输入:intervals = [[1,5]], newInterval = [2,3]
    输出:
    [[1,5]]
    \n

    示例 5:

    \n
    输入:intervals = [[1,5]], newInterval = [2,7]
    输出:
    [[1,7]]
    \n

     

    \n

    提示:

    \n
      \n
    • 0 <= intervals.length <= 104
    • \n
    • intervals[i].length == 2
    • \n
    • 0 <= intervals[i][0] <= intervals[i][1] <= 105
    • \n
    • intervals 根据 intervals[i][0]升序 排列
    • \n
    • newInterval.length == 2
    • \n
    • 0 <= newInterval[0] <= newInterval[1] <= 105
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470920", + "cpp": "#include \n#include \nstatic int compare(const void *a, const void *b)\n{\n\treturn ((int *)a)[0] - ((int *)b)[0];\n}\nint **insert(int **intervals, int intervalsSize, int *intervalsColSize, int *newInterval,\n\t\t\t int newIntervalSize, int *returnSize, int **returnColumnSizes)\n{\n\tint i, len = 0;\n\tint *tmp = malloc((intervalsSize + 1) * 2 * sizeof(int));\n\tfor (i = 0; i < intervalsSize; i++)\n\t{\n\t\ttmp[i * 2] = intervals[i][0];\n\t\ttmp[i * 2 + 1] = intervals[i][1];\n\t}\n\ttmp[i * 2] = newInterval[0];\n\ttmp[i * 2 + 1] = newInterval[1];\n\tqsort(tmp, intervalsSize + 1, 2 * sizeof(int), compare);\n\tint **results = malloc((intervalsSize + 1) * sizeof(int *));\n\tresults[0] = malloc(2 * sizeof(int));\n\tresults[0][0] = tmp[0];\n\tresults[0][1] = tmp[1];\n\tfor (i = 1; i < intervalsSize + 1; i++)\n\t{\n\t\tresults[i] = malloc(2 * sizeof(int));\n\t\tif (tmp[i * 2] > results[len][1])\n\t\t{\n\t\t\tlen++;\n\t\t\tresults[len][0] = tmp[i * 2];\n\t\t\tresults[len][1] = tmp[i * 2 + 1];\n\t\t}\n\t\telse if (tmp[i * 2 + 1] > results[len][1])\n\t\t{\n\t\t\tresults[len][1] = tmp[i * 2 + 1];\n\t\t}\n\t}\n\tlen += 1;\n\t*returnSize = len;\n\t*returnColumnSizes = malloc(len * sizeof(int));\n\tfor (i = 0; i < len; i++)\n\t{\n\t\t(*returnColumnSizes)[i] = 2;\n\t}\n\treturn results;\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 3 || argc % 2 == 0)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test new_s new_e s0 e0 s1 e1...\");\n\t\texit(-1);\n\t}\n\tint new_interv[2];\n\tnew_interv[0] = atoi(argv[1]);\n\tnew_interv[1] = atoi(argv[2]);\n\tint i, count = 0;\n\tint *size = malloc((argc - 3) / 2 * sizeof(int));\n\tint **intervals = malloc((argc - 3) / 2 * sizeof(int *));\n\tfor (i = 0; i < (argc - 3) / 2; i++)\n\t{\n\t\tintervals[i] = malloc(2 * sizeof(int));\n\t\tintervals[i][0] = atoi(argv[i * 2 + 3]);\n\t\tintervals[i][1] = atoi(argv[i * 2 + 4]);\n\t}\n\tint *col_sizes;\n\tint **results = insert(intervals, (argc - 3) / 2, size, new_interv, 2, &count, &col_sizes);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tprintf(\"[%d,%d]\\n\", results[i][0], results[i][1]);\n\t}\n\treturn 0;\n}", + "java": "\npublic class Interval {\n\tint start;\n\tint end;\n\n\tInterval() {\n\t\tstart = 0;\n\t\tend = 0;\n\t}\n\n\tInterval(int s, int e) {\n\t\tstart = s;\n\t\tend = e;\n\t}\n}\n\nclass Solution {\n\tpublic int[][] insert(int[][] intervals, int[] newInterval) {\n\t\tint[][] newIntervals = new int[intervals.length + 1][];\n\t\tSystem.arraycopy(intervals, 0, newIntervals, 0, intervals.length);\n\t\tnewIntervals[intervals.length] = newInterval;\n\n\t\tArrays.sort(newIntervals, (a, b) -> a[0] - b[0]);\n\t\tStack stack = new Stack<>();\n\t\tfor (int[] num : newIntervals) {\n\t\t\tif (stack.isEmpty()) {\n\t\t\t\tstack.push(num);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint[] arr = stack.peek();\n\t\t\tif (arr[1] >= num[0]) {\n\t\t\t\tint[] combine = { arr[0], Math.max(arr[1], num[1]) };\n\t\t\t\tstack.pop();\n\t\t\t\tstack.push(combine);\n\t\t\t} else {\n\t\t\t\tstack.push(num);\n\t\t\t}\n\t\t}\n\t\treturn stack.toArray(new int[0][]);\n\t}\n}\n", + "js": "", + "python": "class Interval(object):\n\tdef __init__(self, s=0, e=0):\n\t\tself.start = s\n\t\tself.end = e\nclass Solution(object):\n\tdef list2interval(self, list_interval):\n\t\tret = []\n\t\tfor i in list_interval:\n\t\t\tinterval = Interval(i[0], i[1])\n\t\t\tret.append(interval)\n\t\treturn ret\n\tdef interval2list(self, interval):\n\t\tret = []\n\t\tx = [0,0]\n\t\tfor i in interval:\n\t\t\tx[0] = i.start\n\t\t\tx[1] = i.end\n\t\t\tret.append(x)\n\t\t\tx = [0,0]\n\t\treturn ret\n\tdef insert(self, intervals, newInterval):\n\t\t\"\"\"\n\t\t:type intervals: List[Interval]\n\t\t:type newInterval: Interval\n\t\t:rtype: List[Interval]\n\t\t\"\"\"\n\t\tif intervals is None or len(intervals) == 0:\n\t\t\treturn [newInterval]\n\t\tintervals = self.list2interval(intervals)\n\t\tnewInterval = Interval(newInterval[0], newInterval[1])\n\t\tintervals.sort(key=lambda x:x.start)\n\t\tpos = 0\n\t\twhile pos < len(intervals):\n\t\t\tif newInterval.end < intervals[pos].start:\n\t\t\t\tintervals.insert(pos, newInterval)\n\t\t\t\tintervals = self.interval2list(intervals)\n\t\t\t\treturn intervals\n\t\t\tif self.check_overlap(intervals[pos], newInterval):\n\t\t\t\ttemp = intervals.pop(pos)\n\t\t\t\tnewInterval = self.merge_intervals(temp, newInterval)\n\t\t\telse:\n\t\t\t\tpos += 1\n\t\tif len(intervals) == 0 or pos == len(intervals):\n\t\t\tintervals.append(newInterval)\n\t\tintervals = self.interval2list(intervals)\n\t\treturn intervals\n\tdef check_overlap(self, curr_int, new_int):\n\t\tif curr_int.start <= new_int.start:\n\t\t if curr_int.end > new_int.start:\n\t\t\t return True\n\t\telse:\n\t\t\tif curr_int.start <= new_int.end:\n\t\t\t\treturn True\n\t\treturn False\n\tdef merge_intervals(self, int1, int2):\n\t\ttemp_int = Interval()\n\t\ttemp_int.start = min([int1.start, int2.start])\n\t\ttemp_int.end = max([int1.end, int2.end])\n\t\treturn temp_int\n# %%\ns = Solution()\nprint(s.insert(intervals = [[1,3],[6,9]], newInterval = [2,5]))", + "status": 1, + "keywords": "数组", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/56/56_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/56/56_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/56/56_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/57.json b/data_backup/leetcode/57.json new file mode 100644 index 000000000..04ec72c70 --- /dev/null +++ b/data_backup/leetcode/57.json @@ -0,0 +1,24 @@ +{ + "question_id": 58, + "question_title": "最后一个单词的长度", + "difficulty": "简单", + "question_content": "

    给你一个字符串 s,由若干单词组成,单词之间用空格隔开。返回字符串中最后一个单词的长度。如果不存在最后一个单词,请返回 0 。

    单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。

     

    示例 1:

    输入:s = \"Hello World\"
    输出:
    5

    示例 2:

    输入:s = \" \"
    输出:
    0

     

    提示:

      \t
    • 1 <= s.length <= 104
    • \t
    • s 仅有英文字母和空格 ' ' 组成
    ", + "topic_link": "https://bbs.csdn.net/topics/600470793", + "cpp": "#include \n#include \nint lengthOfLastWord(char *s)\n{\n\tint len = 0;\n\twhile (*s != '\\0')\n\t{\n\t\tif (s[-1] == ' ' && s[0] != ' ')\n\t\t{\n\t\t\tlen = 1;\n\t\t}\n\t\telse if (*s != ' ')\n\t\t{\n\t\t\tlen++;\n\t\t}\n\t\ts++;\n\t}\n\treturn len;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test word\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%d\\n\", lengthOfLastWord(argv[1]));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int lengthOfLastWord(String s) {\n\t\tint count = 0;\n\t\tfor (int i = s.length() - 1; i >= 0; i--) {\n\t\t\tif (s.charAt(i) != ' ') {\n\t\t\t\tcount++;\n\t\t\t} else if (count > 0) {\n\t\t\t\treturn count;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef lengthOfLastWord(self, s):\n\t\t\"\"\"\n\t\t:type s: str\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tif len(s) == 0:\n\t\t\treturn 0\n\t\ttemp = s.split(' ')\n\t\ttemp = [t for t in temp if len(t) > 0]\n\t\tif len(temp) == 0:\n\t\t\treturn 0\n\t\telse:\n\t\t\treturn len(temp[-1])\n# %%\ns = Solution()\nprint(s.lengthOfLastWord(s = \"Hello World\"))", + "status": 1, + "keywords": "字符串", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_44833195/article/details/106370752" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/57/57_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/57/57_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/57/57_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/58.json b/data_backup/leetcode/58.json new file mode 100644 index 000000000..12a4efd70 --- /dev/null +++ b/data_backup/leetcode/58.json @@ -0,0 +1,24 @@ +{ + "question_id": 59, + "question_title": "螺旋矩阵 II", + "difficulty": "中等", + "question_content": "

    给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix

     

    示例 1:

    \"\"
    输入:n = 3
    输出:
    [[1,2,3],[8,9,4],[7,6,5]]

    示例 2:

    输入:n = 1
    输出:
    [[1]]

     

    提示:

      \t
    • 1 <= n <= 20
    ", + "topic_link": "https://bbs.csdn.net/topics/600470226", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> generateMatrix(int n)\n\t{\n\t\tvector> matrix(n, vector(n));\n\t\tint direction = 0;\n\t\tint hor_top = 0;\n\t\tint hor_bottom = n - 1;\n\t\tint ver_left = 0;\n\t\tint ver_right = n - 1;\n\t\tint num = 0;\n\t\twhile (num < n * n)\n\t\t{\n\t\t\tswitch (direction)\n\t\t\t{\n\t\t\tcase 0:\n\t\t\t\tfor (int i = ver_left; i <= ver_right; i++)\n\t\t\t\t{\n\t\t\t\t\tmatrix[hor_top][i] = ++num;\n\t\t\t\t}\n\t\t\t\thor_top++;\n\t\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\t\tfor (int i = hor_top; i <= hor_bottom; i++)\n\t\t\t\t{\n\t\t\t\t\tmatrix[i][ver_right] = ++num;\n\t\t\t\t}\n\t\t\t\tver_right--;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tfor (int i = ver_right; i >= ver_left; i--)\n\t\t\t\t{\n\t\t\t\t\tmatrix[hor_bottom][i] = ++num;\n\t\t\t\t}\n\t\t\t\thor_bottom--;\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tfor (int i = hor_bottom; i >= hor_top; i--)\n\t\t\t\t{\n\t\t\t\t\tmatrix[i][ver_left] = ++num;\n\t\t\t\t}\n\t\t\t\tver_left++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdirection++;\n\t\t\tdirection %= 4;\n\t\t}\n\t\treturn matrix;\n\t}\n};", + "java": "package LeetCode;\n\npublic class GenerateMatrix {\n\tpublic int[][] generateMatrix(int n) {\n\t\tint[][] res = new int[n][n];\n\t\tif (n == 0) {\n\t\t\treturn res;\n\t\t}\n\t\tint left = 0;\n\t\tint right = n - 1;\n\t\tint up = 0;\n\t\tint down = n - 1;\n\t\tint i = 1;\n\t\twhile (i <= n * n) {\n\n\t\t\tfor (int col = left; col <= right; col++) {\n\t\t\t\tres[up][col] = i;\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\tup++;\n\t\t\tif (i <= n * n) {\n\t\t\t\tfor (int j = up; j <= down; j++) {\n\t\t\t\t\tres[j][right] = i;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tright--;\n\t\t\t}\n\t\t\tif (i <= n * n) {\n\t\t\t\tfor (int j = right; j >= left; j--) {\n\t\t\t\t\tres[down][j] = i;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tdown--;\n\t\t\t}\n\t\t\tif (i <= n * n) {\n\t\t\t\tfor (int j = down; j >= up; j--) {\n\t\t\t\t\tres[j][left] = i;\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tleft++;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tGenerateMatrix a = new GenerateMatrix();\n\t\ta.generateMatrix(3);\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef generateMatrix(self, n):\n\t\t\"\"\"\n\t\t:type n: int\n\t\t:rtype: List[List[int]]\n\t\t\"\"\"\n\t\tres = [[0] * n for _ in range(n)]\n\t\tpos = [0, 0]\n\t\tmove = (0, 1)\n\t\tfor index in range(1, n * n + 1):\n\t\t\tres[pos[0]][pos[1]] = index\n\t\t\tif res[(pos[0] + move[0]) % n][(pos[1] + move[1]) % n] > 0:\n\t\t\t\tmove = (move[1], -1 * move[0])\n\t\t\tpos[0] = pos[0] + move[0]\n\t\t\tpos[1] = pos[1] + move[1]\n\t\treturn res\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.generateMatrix(2))", + "status": 1, + "keywords": "数组,矩阵,模拟", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/58/58_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/58/58_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/58/58_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/59.json b/data_backup/leetcode/59.json new file mode 100644 index 000000000..86a0cb55f --- /dev/null +++ b/data_backup/leetcode/59.json @@ -0,0 +1,24 @@ +{ + "question_id": 60, + "question_title": "排列序列", + "difficulty": "困难", + "question_content": "

    给出集合 [1,2,3,...,n],其所有元素共有 n! 种排列。

    按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下:

      \t
    1. \"123\"
    2. \t
    3. \"132\"
    4. \t
    5. \"213\"
    6. \t
    7. \"231\"
    8. \t
    9. \"312\"
    10. \t
    11. \"321\"

    给定 n 和 k,返回第 k 个排列。

     

    示例 1:

    输入:n = 3, k = 3
    输出:
    \"213\"

    示例 2:

    输入:n = 4, k = 9
    输出:
    \"2314\"

    示例 3:

    输入:n = 3, k = 1
    输出:
    \"123\"

     

    提示:

      \t
    • 1 <= n <= 9
    • \t
    • 1 <= k <= n!
    ", + "topic_link": "https://bbs.csdn.net/topics/600471016", + "cpp": "#include \n#include \n#include \n#include \nstatic char *getPermutation(int n, int k)\n{\n\tint i;\n\tchar *result = malloc(n + 1);\n\tbool *used = malloc(n * sizeof(bool));\n\tmemset(used, false, n * sizeof(bool));\n\tint total = 1;\n\tfor (i = 1; i <= n; i++)\n\t{\n\t\ttotal *= i;\n\t}\n\tk = k - 1;\n\tfor (i = 0; i < n; i++)\n\t{\n\t\ttotal /= (n - i);\n\t\tint gid = k / total;\n\t\tk %= total;\n\t\tint x = -1;\n\t\tint count = 0;\n\t\twhile (count <= gid)\n\t\t{\n\t\t\tx = (x + 1) % n;\n\t\t\tif (!used[x])\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tused[x] = true;\n\t\tresult[i] = x + 1 + '0';\n\t}\n\tresult[n] = '\\0';\n\treturn result;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test n, k\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", getPermutation(atoi(argv[1]), atoi(argv[2])));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic String getPermutation(int n, int k) {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tList candidates = new ArrayList<>();\n\t\tint[] factorials = new int[n + 1];\n\t\tfactorials[0] = 1;\n\t\tint fact = 1;\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tcandidates.add(i);\n\t\t\tfact *= i;\n\t\t\tfactorials[i] = fact;\n\t\t}\n\t\tk -= 1;\n\t\tfor (int i = n - 1; i >= 0; --i) {\n\t\t\tint index = k / factorials[i];\n\t\t\tsb.append(candidates.remove(index));\n\t\t\tk -= index * factorials[i];\n\t\t}\n\t\treturn sb.toString();\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef getPermutation(self, n, k):\n\t\t\"\"\"\n\t\t:type n: int\n\t\t:type k: int\n\t\t:rtype: str\n\t\t\"\"\"\n\t\timport math\n\t\tres=[\"\"]\n\t\tdef generate(s,k):\n\t\t\tn=len(s)\t\n\t\t\tif n<=2:\n\t\t\t\tif k==2:\n\t\t\t\t\tres[0]+=s[::-1]\n\t\t\t\telse:\n\t\t\t\t\tres[0]+=s\n\t\t\t\treturn\n\t\t\tstep = math.factorial(n-1) \n\t\t\tyu=k%step\n\t\t\tif yu==0:\n\t\t\t\tyu=step\n\t\t\t\tc=k//step-1 \n\t\t\telse:\n\t\t\t\tc=k//step\n\t\t\tres[0]+=s[c]\n\t\t\tgenerate(s[:c]+s[c+1:],yu)\n\t\t\treturn \n\t\ts=\"\"\n\t\tfor i in range(1,n+1):\n\t\t\ts+=str(i) \n\t\tgenerate(s,k)\n\t\treturn res[0]\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.getPermutation(3, 2))", + "status": 1, + "keywords": "递归,数学", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104335405" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/59/59_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/59/59_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/59/59_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/6.json b/data_backup/leetcode/6.json new file mode 100644 index 000000000..0953d55b3 --- /dev/null +++ b/data_backup/leetcode/6.json @@ -0,0 +1,24 @@ +{ + "question_id": 7, + "question_title": "整数反转", + "difficulty": "简单", + "question_content": "

    给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。

    如果反转后整数超过 32 位的有符号整数的范围 [−231,  231 − 1] ,就返回 0。

    假设环境不允许存储 64 位整数(有符号或无符号)。

     

    示例 1:

    输入:x = 123
    输出:
    321

    示例 2:

    输入:x = -123
    输出:
    -321

    示例 3:

    输入:x = 120
    输出:
    21

    示例 4:

    输入:x = 0
    输出:
    0

     

    提示:

      \t
    • -231 <= x <= 231 - 1
    ", + "topic_link": "https://bbs.csdn.net/topics/600469815", + "cpp": "int reverse(int x)\n{\n\tlong long int r = 0;\n\twhile (x)\n\t{\n\t\tr = r * 10 + (x % 10);\n\t\tx /= 10;\n\t}\n\tif (r > 2147483647)\n\t\treturn 0;\n\tif (r < -2147483648)\n\t\treturn 0;\n\treturn (int)r;\n}", + "java": "class Solution {\n\tpublic int reverse(int x) {\n\t\tlong xx = x;\n\t\tlong r;\n\t\tlong y = 0;\n\t\tboolean sign = xx < 0;\n\t\twhile (xx != 0) {\n\t\t\tr = xx % 10;\n\t\t\ty = y * 10 + r;\n\t\t\tif (sign) {\n\t\t\t\txx = (long) Math.ceil(xx / 10);\n\t\t\t} else {\n\t\t\t\txx = (long) Math.floor(xx / 10);\n\t\t\t}\n\t\t}\n\t\treturn y > Integer.MAX_VALUE || y < Integer.MIN_VALUE ? 0 : (int) y;\n\t}\n}", + "js": "/**\n * @param {number} x\n * @return {number}\n */\nvar reverse = function(x) {\n \n let r;\n let y=0;\n let sign = x<0;\n while(x!=0){\n r = x%10;\n y=y*10+r;\n if(sign){\n x = Math.ceil(x/10);\n }else{\n x = Math.floor(x/10);\n }\n }\n \n return y > 0x7FFFFFFF || y< -0x7FFFFFFF ? 0 : y;\n};\n\nfunction main(){\n\n}\n\nmain();\n", + "python": "import math\nclass Solution:\n\tdef reverse(self, x: int) -> int:\n\t\tr = 0\n\t\ty = 0\n\t\tabs_x = abs(x)\n\t\tnegative = x < 0\n\t\twhile abs_x != 0:\n\t\t\tr = abs_x % 10\n\t\t\ty = y*10+r\n\t\t\tabs_x = int(math.floor(abs_x/10))\n\t\tif negative:\n\t\t\ty = -y\n\t\treturn 0 if (y > 2147483647 or y < -2147483648) else y\n# %%\ns = Solution()\nprint(s.reverse(x = 123))\nprint(s.reverse(x = -123))", + "status": 1, + "keywords": "数学", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/6/6_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/6/6_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/6/6_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/60.json b/data_backup/leetcode/60.json new file mode 100644 index 000000000..0eb553283 --- /dev/null +++ b/data_backup/leetcode/60.json @@ -0,0 +1,24 @@ +{ + "question_id": 61, + "question_title": "旋转链表", + "difficulty": "中等", + "question_content": "

    给你一个链表的头节点 head ,旋转链表,将链表每个节点向右移动 k 个位置。

     

    示例 1:

    \"\"
    输入:head = [1,2,3,4,5], k = 2
    输出:
    [4,5,1,2,3]

    示例 2:

    \"\"
    输入:head = [0,1,2], k = 4
    输出:
    [2,0,1]

     

    提示:

      \t
    • 链表中节点的数目在范围 [0, 500]
    • \t
    • -100 <= Node.val <= 100
    • \t
    • 0 <= k <= 2 * 109
    ", + "topic_link": "https://bbs.csdn.net/topics/600469922", + "cpp": "#include \nusing namespace std;\nstruct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode() : val(0), next(nullptr) {}\n\tListNode(int x) : val(x), next(nullptr) {}\n\tListNode(int x, ListNode *next) : val(x), next(next) {}\n};\nclass Solution\n{\npublic:\n\tListNode *rotateRight(ListNode *head, int k)\n\t{\n\t\tif (head == nullptr)\n\t\t{\n\t\t\treturn head;\n\t\t}\n\t\tint len = 0;\n\t\tListNode dummy;\n\t\tdummy.next = head;\n\t\tListNode *tail = &dummy;\n\t\twhile (tail->next != nullptr)\n\t\t{\n\t\t\tlen++;\n\t\t\ttail = tail->next;\n\t\t}\n\t\tListNode *prev = &dummy;\n\t\tListNode *p = head;\n\t\tk = k % len;\n\t\tfor (int i = 0; i < len - k; i++)\n\t\t{\n\t\t\tprev = p;\n\t\t\tp = p->next;\n\t\t}\n\t\tif (p != nullptr)\n\t\t{\n\t\t\tprev->next = tail->next;\n\t\t\ttail->next = head;\n\t\t\thead = p;\n\t\t}\n\t\treturn head;\n\t}\n};", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode(int x) {\n\t\tval = x;\n\t}\n}\nclass Solution {\n\tpublic ListNode rotateRight(ListNode head, int k) {\n\t\tif (head == null || k == 0) {\n\t\t\treturn head;\n\t\t}\n\t\tListNode cursor = head;\n\t\tListNode tail = null;\n\t\tint length = 1;\n\t\twhile (cursor.next != null) {\n\t\t\tcursor = cursor.next;\n\t\t\tlength++;\n\t\t}\n\t\tint loop = length - (k % length);\n\t\ttail = cursor;\n\t\tcursor.next = head;\n\t\tcursor = head;\n\t\tfor (int i = 0; i < loop; i++) {\n\t\t\tcursor = cursor.next;\n\t\t\ttail = tail.next;\n\t\t}\n\t\ttail.next = null;\n\t\treturn cursor;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef rotateRight(self, head, k):\n\t\t\"\"\"\n\t\t:type head: ListNode\n\t\t:type k: int\n\t\t:rtype: ListNode\n\t\t\"\"\"\n\t\tif not head or k == 0:\n\t\t\treturn head\n\t\tslow = fast = head\n\t\tlength = 1\n\t\twhile k and fast.next:\n\t\t\tfast = fast.next\n\t\t\tlength += 1\n\t\t\tk -= 1\n\t\tif k != 0:\n\t\t\tk = (k + length - 1) % length \n\t\t\treturn self.rotateRight(head, k)\n\t\telse:\n\t\t\twhile fast.next:\n\t\t\t\tfast = fast.next\n\t\t\t\tslow = slow.next\n\t\t\treturn self.rotate(head, fast, slow)\n\tdef rotate(self, head, fast, slow):\n\t\tfast.next = head\n\t\thead = slow.next\n\t\tslow.next = None\n\t\treturn head\n# %%\nl = LinkList()\nlist1 = [0,1,2]\nk = 4\nl1 = l.initList(list1)\ns = Solution()\nprint(l.convert_list(s.rotateRight(l1, k)))", + "status": 1, + "keywords": "链表,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104336132" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/60/60_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/60/60_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/60/60_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/61.json b/data_backup/leetcode/61.json new file mode 100644 index 000000000..ea06ce923 --- /dev/null +++ b/data_backup/leetcode/61.json @@ -0,0 +1,24 @@ +{ + "question_id": 62, + "question_title": "不同路径", + "difficulty": "中等", + "question_content": "

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。

    \n

    机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。

    \n

    问总共有多少条不同的路径?

    \n

     

    \n

    示例 1:

    \n
    输入:m = 3, n = 7
    输出:
    28
    \n

    示例 2:

    \n
    输入:m = 3, n = 2
    输出:
    3
    解释:
    从左上角开始,总共有 3 条路径可以到达右下角。
    1. 向右 -> 向下 -> 向下
    2. 向下 -> 向下 -> 向右
    3. 向下 -> 向右 -> 向下
    \n

    示例 3:

    \n
    输入:m = 7, n = 3
    输出:
    28
    \n

    示例 4:

    \n
    输入:m = 3, n = 3
    输出:
    6
    \n

     

    \n

    提示:

    \n
      \n
    • 1 <= m, n <= 100
    • \n
    • 题目数据保证答案小于等于 2 * 109
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600469822", + "cpp": "#include \n#include \nstatic int uniquePaths(int m, int n)\n{\n\tint row, col;\n\tint *grids = malloc(m * n * sizeof(int));\n\tfor (col = 0; col < m; col++)\n\t{\n\t\tgrids[col] = 1;\n\t}\n\tfor (row = 0; row < n; row++)\n\t{\n\t\tgrids[row * m] = 1;\n\t}\n\tfor (row = 1; row < n; row++)\n\t{\n\t\tfor (col = 1; col < m; col++)\n\t\t{\n\t\t\tgrids[row * m + col] = grids[row * m + col - 1] + grids[(row - 1) * m + col];\n\t\t}\n\t}\n\treturn grids[m * n - 1];\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test m n\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%d\\n\", uniquePaths(atoi(argv[1]), atoi(argv[2])));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int uniquePaths(int m, int n) {\n\t\tint[][] route = new int[m][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (i == 0 || j == 0) {\n\t\t\t\t\troute[i][j] = 1;\n\t\t\t\t} else {\n\t\t\t\t\troute[i][j] = route[i - 1][j] + route[i][j - 1];\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn route[m - 1][n - 1];\n\t}\n}\n", + "js": "", + "python": "class Solution:\n\tdef uniquePaths(self, m, n):\n\t\t\"\"\"\n\t\t:type m: int\n\t\t:type n: int\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tdmap = [[0] * n for _ in range(m)]\n\t\tfor i in range(m):\n\t\t\tdmap[i][0] = 1\n\t\tfor j in range(n):\n\t\t\tdmap[0][j] = 1\n\t\tfor i in range(1, m):\n\t\t\tfor j in range(1, n):\n\t\t\t\tl = u = 0\n\t\t\t\tif i-1 >= 0:\n\t\t\t\t\tu = dmap[i-1][j]\n\t\t\t\tif j-1>= 0:\n\t\t\t\t\tl = dmap[i][j-1]\n\t\t\t\tdmap[i][j] = l + u\n\t\treturn dmap[m-1][n-1]\n# %%\ns = Solution()\nprint(s.uniquePaths(m = 3, n = 7))", + "status": 1, + "keywords": "数学,动态规划,组合数学", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/61/61_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/61/61_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/61/61_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/62.json b/data_backup/leetcode/62.json new file mode 100644 index 000000000..74d1b388e --- /dev/null +++ b/data_backup/leetcode/62.json @@ -0,0 +1,24 @@ +{ + "question_id": 63, + "question_title": "不同路径 II", + "difficulty": "中等", + "question_content": "

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。

    \n

    机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。

    \n

    现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径?

    \n

    \n

    网格中的障碍物和空位置分别用 10 来表示。

    \n

     

    \n

    示例 1:

    \"\"\n\n
    输入:obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
    输出:
    2
    解释:
    3x3 网格的正中间有一个障碍物。从左上角到右下角一共有 2 条不同的路径:
    1. 向右 -> 向右 -> 向下 -> 向下
    2. 向下 -> 向下 -> 向右 -> 向右
    \n

    示例 2:

    \"\"\n\n
    输入:obstacleGrid = [[0,1],[0,0]]
    输出:
    1
    \n

     

    \n

    提示:

    \n
      \n
    • m == obstacleGrid.length
    • \n
    • n == obstacleGrid[i].length
    • \n
    • 1 <= m, n <= 100
    • \n
    • obstacleGrid[i][j]01
    • \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470123", + "cpp": "#include \n#include \nstatic int uniquePathsWithObstacles(int **obstacleGrid, int obstacleGridRowSize, int obstacleGridColSize)\n{\n\tint row, col;\n\tint reset = 0;\n\tfor (row = 0; row < obstacleGridRowSize; row++)\n\t{\n\t\tif (reset)\n\t\t{\n\t\t\tobstacleGrid[row][0] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (obstacleGrid[row][0] == 1)\n\t\t\t{\n\t\t\t\treset = 1;\n\t\t\t}\n\t\t}\n\t}\n\treset = 0;\n\tfor (col = 0; col < obstacleGridColSize; col++)\n\t{\n\t\tif (reset)\n\t\t{\n\t\t\tobstacleGrid[0][col] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (obstacleGrid[0][col] == 1)\n\t\t\t{\n\t\t\t\treset = 1;\n\t\t\t}\n\t\t}\n\t}\n\tfor (row = 0; row < obstacleGridRowSize; row++)\n\t{\n\t\tint *line = obstacleGrid[row];\n\t\tfor (col = 0; col < obstacleGridColSize; col++)\n\t\t{\n\t\t\tline[col] ^= 1;\n\t\t}\n\t}\n\tfor (row = 1; row < obstacleGridRowSize; row++)\n\t{\n\t\tint *last_line = obstacleGrid[row - 1];\n\t\tint *line = obstacleGrid[row];\n\t\tfor (col = 1; col < obstacleGridColSize; col++)\n\t\t{\n\t\t\tif (line[col] != 0)\n\t\t\t{\n\t\t\t\tline[col] = line[col - 1] + last_line[col];\n\t\t\t}\n\t\t}\n\t}\n\treturn obstacleGrid[obstacleGridRowSize - 1][obstacleGridColSize - 1];\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test m n\\n\");\n\t\texit(-1);\n\t}\n\tint i, j, k = 3;\n\tint row_size = atoi(argv[1]);\n\tint col_size = atoi(argv[2]);\n\tint **grids = malloc(row_size * sizeof(int *));\n\tfor (i = 0; i < row_size; i++)\n\t{\n\t\tgrids[i] = malloc(col_size * sizeof(int));\n\t\tint *line = grids[i];\n\t\tfor (j = 0; j < col_size; j++)\n\t\t{\n\t\t\tline[j] = atoi(argv[k++]);\n\t\t\tprintf(\"%d \", line[j]);\n\t\t}\n\t\tprintf(\"\\n\");\n\t}\n\tprintf(\"%d\\n\", uniquePathsWithObstacles(grids, row_size, col_size));\n\treturn 0;\n}", + "java": "public class Solution {\n\tpublic int uniquePathsWithObstacles(int[][] obstacleGrid) {\n\t\tint m = obstacleGrid.length;\n\t\tint n = obstacleGrid[0].length;\n\t\tif (obstacleGrid[0][0] == 1) {\n\t\t\treturn 0;\n\t\t} else if (m == 1 && n == 1) {\n\t\t\treturn 1;\n\t\t}\n\t\tint[][] paths = new int[m][n];\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tif (obstacleGrid[i][0] == 1) {\n\t\t\t\twhile (i < m) {\n\t\t\t\t\tpaths[i][0] = 0;\n\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tpaths[i][0] = 1;\n\t\t\t}\n\t\t}\n\t\tfor (int j = 1; j < n; ++j) {\n\t\t\tif (obstacleGrid[0][j] == 1) {\n\t\t\t\twhile (j < n) {\n\t\t\t\t\tpaths[0][j] = 0;\n\t\t\t\t\t++j;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tpaths[0][j] = 1;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 1; i < m; ++i)\n\t\t\tfor (int j = 1; j < n; ++j) {\n\t\t\t\tif (obstacleGrid[i][j] == 1) {\n\t\t\t\t\tpaths[i][j] = 0;\n\t\t\t\t} else {\n\t\t\t\t\tpaths[i][j] = paths[i][j - 1] + paths[i - 1][j];\n\t\t\t\t}\n\t\t\t}\n\t\treturn paths[m - 1][n - 1];\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef uniquePathsWithObstacles(self, obstacleGrid):\n\t\tm, n = len(obstacleGrid), len(obstacleGrid[0])\n\t\tif m == 0:\n\t\t\treturn 0\n\t\tdmap = [[0] * (n + 1) for _ in range(m + 1)]\n\t\tdmap[m - 1][n] = 1\n\t\tfor i in range(m - 1, -1, -1):\n\t\t\tfor j in range(n - 1, -1, -1):\n\t\t\t\tif obstacleGrid[i][j] == 1:\n\t\t\t\t\tdmap[i][j] = 0\n\t\t\t\telse:\n\t\t\t\t\tdmap[i][j] = dmap[i][j + 1] + dmap[i + 1][j]\n\t\treturn dmap[0][0]\n# %%\ns = Solution()\nprint(s.uniquePathsWithObstacles(obstacleGrid = [[0,1],[0,0]]))", + "status": 1, + "keywords": "数组,动态规划,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/lilong_dream/article/details/19931301" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/62/62_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/62/62_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/62/62_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/63.json b/data_backup/leetcode/63.json new file mode 100644 index 000000000..8960c5957 --- /dev/null +++ b/data_backup/leetcode/63.json @@ -0,0 +1,24 @@ +{ + "question_id": 64, + "question_title": "最小路径和", + "difficulty": "中等", + "question_content": "

    给定一个包含非负整数的 m x n 网格 grid ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。

    说明:每次只能向下或者向右移动一步。

     

    示例 1:

    \"\"
    输入:grid = [[1,3,1],[1,5,1],[4,2,1]]
    输出:
    7
    解释:
    因为路径 1→3→1→1→1 的总和最小。

    示例 2:

    输入:grid = [[1,2,3],[4,5,6]]
    输出:
    12

     

    提示:

      \t
    • m == grid.length
    • \t
    • n == grid[i].length
    • \t
    • 1 <= m, n <= 200
    • \t
    • 0 <= grid[i][j] <= 100
    ", + "topic_link": "https://bbs.csdn.net/topics/600470227", + "cpp": "#include \n#include \n#include \nstatic inline int min(int a, int b)\n{\n\treturn a < b ? a : b;\n}\nint minPathSum(int **grid, int gridRowSize, int gridColSize)\n{\n\tint i, j;\n\tint **dp = malloc(gridRowSize * sizeof(int *));\n\tfor (i = 0; i < gridRowSize; i++)\n\t{\n\t\tdp[i] = malloc(gridColSize * sizeof(int));\n\t}\n\tdp[0][0] = grid[0][0];\n\tint sum = dp[0][0];\n\tfor (i = 1; i < gridRowSize; i++)\n\t{\n\t\tsum += grid[i][0];\n\t\tdp[i][0] = sum;\n\t}\n\tsum = dp[0][0];\n\tfor (i = 1; i < gridColSize; i++)\n\t{\n\t\tsum += grid[0][i];\n\t\tdp[0][i] = sum;\n\t}\n\tfor (i = 1; i < gridRowSize; i++)\n\t{\n\t\tfor (j = 1; j < gridColSize; j++)\n\t\t{\n\t\t\tdp[i][j] = grid[i][j] + min(dp[i - 1][j], dp[i][j - 1]);\n\t\t}\n\t}\n\treturn dp[gridRowSize - 1][gridColSize - 1];\n}\nint main(int argc, char **argv)\n{\n\tint i, j;\n\tint row = argc - 1;\n\tint col = strlen(argv[1]);\n\tint **grid = malloc(row * sizeof(int *));\n\tfor (i = 0; i < row; i++)\n\t{\n\t\tgrid[i] = malloc(col * sizeof(int));\n\t\tfor (j = 0; j < col; j++)\n\t\t{\n\t\t\tgrid[i][j] = argv[i + 1][j] - '0';\n\t\t\tprintf(\"%d \", grid[i][j]);\n\t\t}\n\t\tprintf(\"\\n\");\n\t}\n\tprintf(\"%d\\n\", minPathSum(grid, row, col));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int minPathSum(int[][] grid) {\n\t\tint m = grid.length;\n\t\tint n = grid[0].length;\n\n\t\tint sum = 0;\n\n\t\tif (m < 1 || n < 1)\n\t\t\treturn 0;\n\t\tif (m == 1) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tsum = sum + grid[0][i];\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t\tif (n == 1) {\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tsum = sum + grid[i][0];\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\n\t\tint[][] dp = new int[m][n];\n\t\tdp[0][0] = grid[0][0];\n\n\t\tfor (int k = 1; k < m; k++) {\n\t\t\tdp[k][0] = grid[k][0] + dp[k - 1][0];\n\t\t}\n\n\t\tfor (int l = 1; l < n; l++) {\n\t\t\tdp[0][l] = grid[0][l] + dp[0][l - 1];\n\t\t}\n\n\t\tfor (int k = 1; k < m; k++) {\n\t\t\tfor (int l = 1; l < n; l++) {\n\t\t\t\tdp[k][l] = grid[k][l] + Math.min(dp[k - 1][l], dp[k][l - 1]);\n\t\t\t}\n\t\t}\n\t\treturn dp[m - 1][n - 1];\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef minPathSum(self, grid):\n\t\t\"\"\"\n\t\t:type grid: List[List[int]]\n\t\t:rtype: int\n\t\t\"\"\"\n\t\theight = len(grid)\n\t\tif height == 0:\n\t\t\treturn 0\n\t\twidth = len(grid[0])\n\t\tpathmap = []\n\t\tfor i in range(height):\n\t\t\tpathmap.append([100000000000] * width)\n\t\tpathmap[0][0] = grid[0][0]\n\t\tfor i in range(height):\n\t\t\tfor j in range(width):\n\t\t\t\tcompare = [pathmap[i][j]]\n\t\t\t\tif i - 1 >= 0:\n\t\t\t\t\tcompare.append(pathmap[i - 1][j] + grid[i][j])\n\t\t\t\tif j - 1 >= 0:\n\t\t\t\t\tcompare.append(pathmap[i][j - 1] + grid[i][j])\n\t\t\t\tpathmap[i][j] = min(compare)\n\t\treturn pathmap[-1][-1]\n# %%\ns = Solution()\nprint(s.minPathSum(grid = [[1,3,1],[1,5,1],[4,2,1]]))", + "status": 1, + "keywords": "数组,动态规划,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/63/63_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/63/63_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/63/63_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/64.json b/data_backup/leetcode/64.json new file mode 100644 index 000000000..ed32e1a01 --- /dev/null +++ b/data_backup/leetcode/64.json @@ -0,0 +1,24 @@ +{ + "question_id": 65, + "question_title": "有效数字", + "difficulty": "困难", + "question_content": "

    有效数字(按顺序)可以分成以下几个部分:

      \t
    1. 一个 小数 或者 整数
    2. \t
    3. (可选)一个 'e''E' ,后面跟着一个 整数

    小数(按顺序)可以分成以下几个部分:

      \t
    1. (可选)一个符号字符('+''-'
    2. \t
    3. 下述格式之一:\t
        \t\t
      1. 至少一位数字,后面跟着一个点 '.'
      2. \t\t
      3. 至少一位数字,后面跟着一个点 '.' ,后面再跟着至少一位数字
      4. \t\t
      5. 一个点 '.' ,后面跟着至少一位数字
      6. \t
      \t

    整数(按顺序)可以分成以下几个部分:

      \t
    1. (可选)一个符号字符('+''-'
    2. \t
    3. 至少一位数字

    部分有效数字列举如下:

      \t
    • [\"2\", \"0089\", \"-0.1\", \"+3.14\", \"4.\", \"-.9\", \"2e10\", \"-90E3\", \"3e+7\", \"+6e-1\", \"53.5e93\", \"-123.456e789\"]

    部分无效数字列举如下:

      \t
    • [\"abc\", \"1a\", \"1e\", \"e3\", \"99e2.5\", \"--6\", \"-+3\", \"95a54e53\"]

    给你一个字符串 s ,如果 s 是一个 有效数字 ,请返回 true

     

    示例 1:

    输入:s = \"0\"
    输出:
    true

    示例 2:

    输入:s = \"e\"
    输出:
    false

    示例 3:

    输入:s = \".\"
    输出:
    false

    示例 4:

    输入:s = \".1\"
    输出:
    true

     

    提示:

      \t
    • 1 <= s.length <= 20
    • \t
    • s 仅含英文字母(大写和小写),数字(0-9),加号 '+' ,减号 '-' ,或者点 '.'
    ", + "topic_link": "https://bbs.csdn.net/topics/600470924", + "cpp": "#include \n#include \n#include \n#include \nstatic bool isNumber(const char *s)\n{\n\twhile (*s == ' ')\n\t\t++s;\n\tbool if_find_num = false;\n\tif (*s == '-' || *s == '+')\n\t\t++s;\n\twhile (isdigit(*s))\n\t{\n\t\tif_find_num = true;\n\t\t++s;\n\t}\n\tif (*s == '.')\n\t\t++s;\n\twhile (isdigit(*s))\n\t{\n\t\tif_find_num = true;\n\t\t++s;\n\t}\n\tif (if_find_num == true && *s == 'e')\n\t{\n\t\t++s;\n\t\tif (*s == '+' || *s == '-')\n\t\t\t++s;\n\t\tif_find_num = false;\n\t\twhile (isdigit(*s))\n\t\t{\n\t\t\tif_find_num = true;\n\t\t\t++s;\n\t\t}\n\t}\n\twhile (*s == ' ')\n\t\t++s;\n\treturn *s == '\\0' && if_find_num == true;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test number\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", isNumber(argv[1]) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tchar[] chars;\n\tboolean point = false;\n\tboolean exponent = false;\n\tpublic boolean isNumber(String s) {\n\t\ts = s.trim();\n\t\tint length = s.length();\n\t\tif (length == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tchars = s.toCharArray();\n\t\tString[] ss = s.split(\"e\");\n\t\tif (ss.length == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tif (ss[0].length() == 0)\n\t\t\treturn false;\n\t\tif (ss[0].length() < length)\n\t\t\texponent = true;\n\t\tif (ss[0].length() == length - 1) {\n\t\t\treturn false;\n\t\t}\n\t\tString[] pre = ss[0].split(\"\\\\.\");\n\t\tif (pre.length == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tif (pre[0].length() < ss[0].length())\n\t\t\tpoint = true;\n\t\tboolean result = pre(0, pre[0].length());\n\t\tresult = result && middle(pre[0].length() + 1, ss[0].length());\n\t\tif (exponent) {\n\t\t\tresult = result && is(ss[0].length() + 1, length);\n\t\t}\n\t\treturn result;\n\t}\n\tpublic boolean pre(int i, int length) {\n\t\tif (i >= length) {\n\t\t\treturn true;\n\t\t}\n\t\tif (chars[i] == '+' || chars[i] == '-') {\n\t\t\ti++;\n\t\t}\n\t\tif (i == length && !point) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (; i < length; i++) {\n\t\t\tif (chars[i] < '0' || chars[i] > '9') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\tpublic boolean middle(int i, int length) {\n\t\tif (i >= length && point) {\n\t\t\tif (chars[i - 2] >= '0' && chars[i - 2] <= '9') {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tfor (; i < length; i++) {\n\t\t\tif (chars[i] < '0' || chars[i] > '9') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\tpublic boolean is(int i, int length) {\n\t\tif (i == 1) {\n\t\t\treturn false;\n\t\t}\n\t\tif (chars[i] == '+' || chars[i] == '-') {\n\t\t\ti++;\n\t\t}\n\t\tif (i == length) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (; i < length; i++) {\n\t\t\tif (chars[i] < '0' || chars[i] > '9') {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef isNumber(self, s):\n\t\ts = s.strip()\n\t\tls, pos = len(s), 0\n\t\tif ls == 0:\n\t\t\treturn False\n\t\tif s[pos] == '+' or s[pos] == '-':\n\t\t\tpos += 1\n\t\tisNumeric = False\n\t\twhile pos < ls and s[pos].isdigit():\n\t\t\tpos += 1\n\t\t\tisNumeric = True\n\t\tif pos < ls and s[pos] == '.':\n\t\t\tpos += 1\n\t\t\twhile pos < ls and s[pos].isdigit():\n\t\t\t\tpos += 1\n\t\t\t\tisNumeric = True\n\t\telif pos < ls and s[pos] == 'e' and isNumeric:\n\t\t\tisNumeric = False\n\t\t\tpos += 1\n\t\t\tif pos < ls and (s[pos] == '+' or s[pos] == '-'):\n\t\t\t\tpos += 1\n\t\t\twhile pos < ls and s[pos].isdigit():\n\t\t\t\tpos += 1\n\t\t\t\tisNumeric = True\n\t\tif pos == ls and isNumeric:\n\t\t\treturn True\n\t\treturn False\n# %%\ns = Solution()\nprint(s.isNumber(s = \"0\"))", + "status": 1, + "keywords": "字符串", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104340910" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/64/64_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/64/64_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/64/64_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/65.json b/data_backup/leetcode/65.json new file mode 100644 index 000000000..5fcd0dbb9 --- /dev/null +++ b/data_backup/leetcode/65.json @@ -0,0 +1,24 @@ +{ + "question_id": 66, + "question_title": "加一", + "difficulty": "简单", + "question_content": "

    给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一。

    最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。

    你可以假设除了整数 0 之外,这个整数不会以零开头。

     

    示例 1:

    输入:digits = [1,2,3]
    输出:
    [1,2,4]
    解释:
    输入数组表示数字 123。

    示例 2:

    输入:digits = [4,3,2,1]
    输出:
    [4,3,2,2]
    解释:
    输入数组表示数字 4321。

    示例 3:

    输入:digits = [0]
    输出:
    [1]

     

    提示:

      \t
    • 1 <= digits.length <= 100
    • \t
    • 0 <= digits[i] <= 9
    ", + "topic_link": "https://bbs.csdn.net/topics/600469823", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector plusOne(vector &digits)\n\t{\n\t\tint carry = 1;\n\t\tvector res;\n\t\tfor (int i = digits.size() - 1; i >= 0; i--)\n\t\t{\n\t\t\tint d = digits[i] + carry;\n\t\t\tres.push_back(d % 10);\n\t\t\tcarry = d / 10;\n\t\t}\n\t\tif (carry > 0)\n\t\t{\n\t\t\tres.push_back(carry);\n\t\t}\n\t\treverse(res.begin(), res.end());\n\t\treturn res;\n\t}\n};", + "java": "class Solution {\n\tpublic int[] plusOne(int[] digits) {\n\t\tint i = digits.length - 1;\n\t\twhile (i >= 0 && (digits[i] = digits[i] + 1) == 10) {\n\t\t\tdigits[i] = 0;\n\t\t\ti--;\n\t\t}\n\t\tif (digits[0] == 0) {\n\t\t\tint[] temp = new int[digits.length + 1];\n\t\t\ttemp[0] = 1;\n\t\t\treturn temp;\n\t\t}\n\t\treturn digits;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef plusOne(self, digits):\n\t\tls = len(digits)\n\t\tfor index in reversed(range(ls)):\n\t\t\tif digits[index] < 9:\n\t\t\t\tdigits[index] += 1\n\t\t\t\treturn digits\n\t\t\telse:\n\t\t\t\tdigits[index] = 0\n\t\tdigits.insert(0, 1)\n\t\treturn digits\n# %%\ns = Solution()\nprint(s.plusOne(digits = [1,2,3]))", + "status": 1, + "keywords": "数组,数学", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/65/65_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/65/65_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/65/65_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/66.json b/data_backup/leetcode/66.json new file mode 100644 index 000000000..0345903f7 --- /dev/null +++ b/data_backup/leetcode/66.json @@ -0,0 +1,24 @@ +{ + "question_id": 67, + "question_title": "二进制求和", + "difficulty": "简单", + "question_content": "

    给你两个二进制字符串,返回它们的和(用二进制表示)。

    输入为 非空 字符串且只包含数字 1 和 0

     

    示例 1:

    输入: a = "11", b = "1"
    输出:
    "100"

    示例 2:

    输入: a = "1010", b = "1011"
    输出:
    "10101"

     

    提示:

      \t
    • 每个字符串仅由字符 '0''1' 组成。
    • \t
    • 1 <= a.length, b.length <= 10^4
    • \t
    • 字符串如果不是 "0" ,就都不含前导零。
    ", + "topic_link": "https://bbs.csdn.net/topics/600471009", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tstring addBinary(string a, string b)\n\t{\n\t\tstring res;\n\t\tint carry = 0;\n\t\tint i = a.length() - 1;\n\t\tint j = b.length() - 1;\n\t\tfor (; i >= 0 && j >= 0; i--, j--)\n\t\t{\n\t\t\tif (a[i] == '1' && b[j] == '1')\n\t\t\t{\n\t\t\t\tif (carry > 0)\n\t\t\t\t{\n\t\t\t\t\tres.push_back('1');\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres.push_back('0');\n\t\t\t\t}\n\t\t\t\tcarry = 1;\n\t\t\t}\n\t\t\telse if (a[i] == '0' && b[j] == '0')\n\t\t\t{\n\t\t\t\tif (carry > 0)\n\t\t\t\t{\n\t\t\t\t\tres.push_back('1');\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres.push_back('0');\n\t\t\t\t}\n\t\t\t\tcarry = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (carry > 0)\n\t\t\t\t{\n\t\t\t\t\tres.push_back('0');\n\t\t\t\t\tcarry = 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres.push_back('1');\n\t\t\t\t\tcarry = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twhile (i >= 0)\n\t\t{\n\t\t\tif (a[i--] == '1')\n\t\t\t{\n\t\t\t\tif (carry > 0)\n\t\t\t\t{\n\t\t\t\t\tres.push_back('0');\n\t\t\t\t\tcarry = 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres.push_back('1');\n\t\t\t\t\tcarry = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres.push_back(carry + '0');\n\t\t\t\tcarry = 0;\n\t\t\t}\n\t\t}\n\t\twhile (j >= 0)\n\t\t{\n\t\t\tif (b[j--] == '1')\n\t\t\t{\n\t\t\t\tif (carry > 0)\n\t\t\t\t{\n\t\t\t\t\tres.push_back('0');\n\t\t\t\t\tcarry = 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres.push_back('1');\n\t\t\t\t\tcarry = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres.push_back(carry + '0');\n\t\t\t\tcarry = 0;\n\t\t\t}\n\t\t}\n\t\tif (carry > 0)\n\t\t{\n\t\t\tres.push_back('1');\n\t\t}\n\t\treverse(res.begin(), res.end());\n\t\treturn res;\n\t}\n};", + "java": "class Solution {\n\tpublic String addBinary(String a, String b) {\n\n\t\tStringBuffer s1 = new StringBuffer(a);\n\t\ts1.reverse();\n\t\tStringBuffer s2 = new StringBuffer(b);\n\t\ts2.reverse();\n\n\t\tif (s1.length() > s2.length()) {\n\t\t\tint n = s1.length() - s2.length();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ts2.append('0');\n\t\t\t}\n\t\t} else if (s1.length() < s2.length()) {\n\t\t\tint n = s2.length() - s1.length();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ts1.append('0');\n\t\t\t}\n\t\t}\n\n\t\tStringBuffer stringBuffer = new StringBuffer(\"\");\n\t\tint i = 0;\n\t\tchar flag = '0';\n\t\twhile (i < s1.length() && i < s2.length()) {\n\t\t\tif (flag == '0') {\n\t\t\t\tif (s1.charAt(i) == s2.charAt(i) && s1.charAt(i) == '1') {\n\t\t\t\t\tflag = '1';\n\t\t\t\t\tstringBuffer.append('0');\n\t\t\t\t} else if (s1.charAt(i) == s2.charAt(i) && s1.charAt(i) == '0') {\n\t\t\t\t\tstringBuffer.append('0');\n\t\t\t\t} else {\n\t\t\t\t\tstringBuffer.append('1');\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (s1.charAt(i) == s2.charAt(i) && s1.charAt(i) == '1') {\n\t\t\t\t\tflag = '1';\n\t\t\t\t\tstringBuffer.append('1');\n\t\t\t\t} else if (s1.charAt(i) == s2.charAt(i) && s1.charAt(i) == '0') {\n\t\t\t\t\tflag = '0';\n\t\t\t\t\tstringBuffer.append('1');\n\t\t\t\t} else {\n\t\t\t\t\tflag = '1';\n\t\t\t\t\tstringBuffer.append('0');\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tif (flag == '1') {\n\t\t\tstringBuffer.append(flag);\n\t\t}\n\t\tstringBuffer.reverse();\n\t\treturn stringBuffer.toString();\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef addBinary(self, a, b):\n\t\tres = ''\n\t\tlsa, lsb = len(a), len(b)\n\t\tpos, plus, curr = -1, 0, 0\n\t\twhile (lsa + pos) >= 0 or (lsb + pos) >= 0:\n\t\t\tif (lsa + pos) >= 0:\n\t\t\t\tcurr += int(a[pos])\n\t\t\tif (lsb + pos) >= 0:\n\t\t\t\tcurr += int(b[pos])\n\t\t\tres = str(curr % 2) + res\n\t\t\tcurr //= 2\n\t\t\tpos -= 1\n\t\tif curr == 1:\n\t\t\tres = '1' + res\n\t\treturn res\n# %%\ns = Solution()\nprint(s.addBinary(a = \"1010\", b = \"1011\"))", + "status": 1, + "keywords": "位运算,数学,字符串,模拟", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/66/66_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/66/66_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/66/66_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/67.json b/data_backup/leetcode/67.json new file mode 100644 index 000000000..9738ff3e0 --- /dev/null +++ b/data_backup/leetcode/67.json @@ -0,0 +1,24 @@ +{ + "question_id": 68, + "question_title": "文本左右对齐", + "difficulty": "困难", + "question_content": "
    \n

    给定一个单词数组和一个长度 maxWidth,重新排版单词,使其成为每行恰好有 maxWidth 个字符,且左右两端对齐的文本。

    \n\n

    你应该使用“贪心算法”来放置给定的单词;也就是说,尽可能多地往每行中放置单词。必要时可用空格 ' ' 填充,使得每行恰好有 maxWidth 个字符。\n

    \n\n

    要求尽可能均匀分配单词间的空格数量。如果某一行单词间的空格不能均匀分配,则左侧放置的空格数要多于右侧的空格数。

    \n\n

    文本的最后一行应为左对齐,且单词之间不插入额外的空格。

    \n\n

    说明:

    \n\n
      \n
    • 单词是指由非空格字符组成的字符序列。
    • \n
    • 每个单词的长度大于 0,小于等于 maxWidth
    • \n
    • 输入单词数组 words 至少包含一个单词。
    • \n
    \n\n

    示例:

    \n\n
    输入:\n    words = [\"This\", \"is\", \"an\", \"example\", \"of\", \"text\", \"justification.\"]\n    maxWidth = 16\n输出:\n    [\n       \"This    is    an\",\n       \"example  of text\",\n       \"justification.  \"\n    ]\n    
    \n\n

    示例 2:

    \n\n
    输入:\n    words = [\"What\",\"must\",\"be\",\"acknowledgment\",\"shall\",\"be\"]\n    maxWidth = 16\n输出:\n    [\n      \"What   must   be\",\n      \"acknowledgment  \",\n      \"shall be        \"\n    ]\n解释: 注意最后一行的格式应为 \"shall be    \" 而不是 \"shall     be\"\n    因为最后一行应为左对齐,而不是左右两端对齐,第二行同样为左对齐,这是因为这行只包含一个单词。\n    
    \n\n

    示例 3:

    \n\n
    输入:\n    words = [\"Science\",\"is\",\"what\",\"we\",\"understand\",\"well\",\"enough\",\"to\",\"explain\",\n             \"to\",\"a\",\"computer.\",\"Art\",\"is\",\"everything\",\"else\",\"we\",\"do\"]\n    maxWidth = 20\n输出:\n    [\n      \"Science  is  what we\",\n      \"understand      well\",\n      \"enough to explain to\",\n      \"a  computer.  Art is\",\n      \"everything  else  we\",\n      \"do                  \"\n    ]\n    
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470798", + "cpp": "#include \n#include \n#include \nstatic void line_fill(char *line, int len, char **words, int *word_lens, int max_size,\n\t\t\t\t\t int even_spaces, int remain_spaces, int start, int end)\n{\n\tint i, j;\n\tchar *p = line;\n\tfor (i = start; i < end; i++)\n\t{\n\t\tmemcpy(p, words[i], word_lens[i]);\n\t\tp += word_lens[i];\n\t\tif (i < end - 1)\n\t\t{\n\t\t\tfor (j = 0; j < even_spaces; j++)\n\t\t\t{\n\t\t\t\t*p++ = ' ';\n\t\t\t}\n\t\t\tif (remain_spaces > 0)\n\t\t\t{\n\t\t\t\t*p++ = ' ';\n\t\t\t\tremain_spaces--;\n\t\t\t}\n\t\t}\n\t}\n\twhile (p - line < max_size)\n\t{\n\t\t*p++ = ' ';\n\t}\n\t*p++ = '\\0';\n}\nstatic char **fullJustify(char **words, int wordsSize, int maxWidth, int *returnSize)\n{\n\tint i, j, k, cap = 100, count = 0;\n\tchar **lines = malloc(cap * sizeof(char *));\n\tchar *buf = malloc(cap * (maxWidth + 1));\n\tfor (i = 0; i < cap; i++)\n\t{\n\t\tlines[i] = buf + i * (maxWidth + 1);\n\t}\n\tint *word_lens = malloc(wordsSize * sizeof(int));\n\tfor (i = 0; i < wordsSize; i++)\n\t{\n\t\tword_lens[i] = strlen(words[i]);\n\t}\n\tint wc = 0;\n\tint len = 0;\n\tint start = 0;\n\tint chars = 0;\n\tfor (i = 0, j = 0; i < wordsSize; i++)\n\t{\n\t\tif (len + word_lens[i] > maxWidth)\n\t\t{\n\t\t\tint even_spaces = wc == 1 ? 0 : (maxWidth - chars) / (wc - 1);\n\t\t\tint remain_spaces = wc == 1 ? 0 : (maxWidth - chars) % (wc - 1);\n\t\t\tline_fill(lines[count], len, words, word_lens, maxWidth, even_spaces, remain_spaces, start, i);\n\t\t\tcount++;\n\t\t\twc = 1;\n\t\t\tlen = word_lens[i] + 1;\n\t\t\tchars = word_lens[i];\n\t\t\tstart = i;\n\t\t}\n\t\telse if (len + word_lens[i] == maxWidth)\n\t\t{\n\t\t\tchars += word_lens[i];\n\t\t\tint even_spaces = wc == 0 ? 0 : (maxWidth - chars) / wc;\n\t\t\tint remain_spaces = wc == 0 ? 0 : (maxWidth - chars) % wc;\n\t\t\tline_fill(lines[count], len, words, word_lens, maxWidth, even_spaces, remain_spaces, start, i + 1);\n\t\t\tcount++;\n\t\t\twc = 0;\n\t\t\tlen = 0;\n\t\t\tchars = 0;\n\t\t\tstart = i + 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tchars += word_lens[i];\n\t\t\tlen += word_lens[i] + 1;\n\t\t\twc++;\n\t\t}\n\t}\n\tif (wc > 0)\n\t{\n\t\tchar *p = lines[count];\n\t\tfor (i = start; i < start + wc; i++)\n\t\t{\n\t\t\tmemcpy(p, words[i], word_lens[i]);\n\t\t\tp += word_lens[i];\n\t\t\tif (i < start + wc - 1)\n\t\t\t{\n\t\t\t\t*p++ = ' ';\n\t\t\t}\n\t\t}\n\t\twhile (p - lines[count] < maxWidth)\n\t\t{\n\t\t\t*p++ = ' ';\n\t\t}\n\t\t*p++ = '\\0';\n\t\tcount++;\n\t}\n\t*returnSize = count;\n\treturn lines;\n}\nint main(int argc, char **argv)\n{\n\tif (argc <= 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test maxsize words...\\n\");\n\t\texit(-1);\n\t}\n\tint i, count;\n\tchar **lines = fullJustify(argv + 2, argc - 2, atoi(argv[1]), &count);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tprintf(\"%s\\n\", lines[i]);\n\t}\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic List fullJustify(String[] words, int maxWidth) {\n\t\tList ret = new ArrayList<>();\n\t\tint index = 0;\n\t\twhile (index < words.length) {\n\t\t\tint cur = index, len = 0;\n\t\t\twhile (cur < words.length && len + words[cur].length() + cur - index <= maxWidth) {\n\t\t\t\tlen = len + words[cur++].length();\n\t\t\t}\n\t\t\tcur--;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tif (cur == words.length - 1) {\n\t\t\t\tfor (int i = index; i <= cur; i++) {\n\t\t\t\t\tsb.append(words[i]);\n\t\t\t\t\tif (i < cur) {\n\t\t\t\t\t\tsb.append(' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tint base = cur > index ? (maxWidth - len) / (cur - index) : (maxWidth - len);\n\t\t\t\tString baseStr = genSpace(base);\n\t\t\t\tint left = cur > index ? (maxWidth - len) % (cur - index) : 0;\n\t\t\t\tString leftStr = genSpace(base + 1);\n\t\t\t\tfor (int i = index; i <= cur; i++) {\n\t\t\t\t\tsb.append(words[i]);\n\t\t\t\t\tif (i < cur) {\n\t\t\t\t\t\tsb.append(left > 0 ? leftStr : baseStr);\n\t\t\t\t\t\tleft--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (sb.length() < maxWidth) {\n\t\t\t\tsb.append(genSpace(maxWidth - sb.length()));\n\t\t\t}\n\t\t\tret.add(sb.toString());\n\t\t\tindex = cur + 1;\n\t\t}\n\t\treturn ret;\n\t}\n\tprivate String genSpace(int n) {\n\t\tchar[] cs = new char[n];\n\t\tArrays.fill(cs, ' ');\n\t\treturn new String(cs);\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef fullJustify(self, words, maxWidth):\n\t\t\"\"\"\n\t\t:type words: List[str]\n\t\t:type maxWidth: int\n\t\t:rtype: List[str]\n\t\t\"\"\"\n\t\tres = []\n\t\tres_list = []\n\t\tcurr = []\n\t\tcount, pos = 0, 0\n\t\twhile pos < len(words):\n\t\t\tword = words[pos]\n\t\t\tif len(word) > maxWidth:\n\t\t\t\tpos += 1\n\t\t\tif len(word) + count + len(curr)<= maxWidth:\n\t\t\t\tcount += len(word)\n\t\t\t\tcurr.append(word)\n\t\t\t\tpos += 1\n\t\t\telse:\n\t\t\t\tres_list.append(curr)\n\t\t\t\tcurr = []\n\t\t\t\tcount = 0\n\t\tif len(curr) > 0:\n\t\t\tres_list.append(curr)\n\t\tfor index, curr in enumerate(res_list):\n\t\t\ttext = ''\n\t\t\tremain = sum([len(t) for t in curr])\n\t\t\tif len(curr) == 1:\n\t\t\t\ttext = curr[0] + ' ' * (maxWidth - remain)\n\t\t\telif index == len(res_list) - 1:\n\t\t\t\ttext = ' '.join(curr)\n\t\t\t\ttext += ' ' * (maxWidth - remain - len(curr) + 1)\n\t\t\telse:\n\t\t\t\tstep = (maxWidth - remain) / (len(curr) - 1 )\n\t\t\t\textra = (maxWidth - remain) % (len(curr) - 1 )\n\t\t\t\tfor index in range(len(curr) - 1):\n\t\t\t\t\ttext += curr[index] + ' ' * int(step)\n\t\t\t\t\tif extra > 0:\n\t\t\t\t\t\ttext += ' '\n\t\t\t\t\t\textra -= 1\n\t\t\t\ttext += curr[-1]\n\t\t\tres.append(text)\n\t\treturn res\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.fullJustify([\"Don't\",\"go\",\"around\",\"saying\",\"the\",\"world\",\"owes\",\"you\",\"a\",\"living;\",\"the\",\"world\",\"owes\",\"you\",\"nothing;\",\"it\",\"was\",\"here\",\"first.\"],30))", + "status": 1, + "keywords": "字符串,模拟", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104341710" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/67/67_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/67/67_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/67/67_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/68.json b/data_backup/leetcode/68.json new file mode 100644 index 000000000..b4f705edb --- /dev/null +++ b/data_backup/leetcode/68.json @@ -0,0 +1,24 @@ +{ + "question_id": 69, + "question_title": "x 的平方根", + "difficulty": "简单", + "question_content": "

    实现 int sqrt(int x) 函数。

    \n

    计算并返回 x 的平方根,其中 x 是非负整数。

    \n

    由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。

    \n

    示例 1:

    \n
    输入: 4
    输出:
    2
    \n

    示例 2:

    \n
    输入: 8
    输出:
    2
    说明:
    8 的平方根是 2.82842..., 由于返回类型是整数,小数部分将被舍去。
    ", + "topic_link": "https://bbs.csdn.net/topics/600470124", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint mySqrt(int x)\n\t{\n\t\tif (x == 0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\tunsigned int lo = 1, hi = x;\n\t\tunsigned int mid = (lo + hi) / 2;\n\t\tfor (;;)\n\t\t{\n\t\t\tif (mid > x / mid)\n\t\t\t{\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (mid + 1 > x / (mid + 1))\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlo = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmid = (lo + hi) / 2;\n\t\t}\n\t\treturn mid;\n\t}\n};", + "java": "class Solution {\n\tpublic int mySqrt(int x) {\n\t\tint left = 0, right = 46340;\n\t\twhile (left < right) {\n\t\t\tint mid = (left + right) / 2;\n\t\t\tif (mid * mid < x)\n\t\t\t\tleft = mid + 1;\n\t\t\telse if (mid * mid > x)\n\t\t\t\tif ((mid - 1) * (mid - 1) <= x)\n\t\t\t\t\treturn mid - 1;\n\t\t\t\telse\n\t\t\t\t\tright = mid - 1;\n\t\t\telse\n\t\t\t\treturn mid;\n\t\t}\n\t\tif (left * left > x)\n\t\t\treturn left - 1;\n\t\treturn left;\n\t}\n}\n", + "js": "", + "python": "class Solution:\n\tdef mySqrt(self, x):\n\t\tif x == 0:\n\t\t\treturn 0\n\t\tif x < 4:\n\t\t\treturn 1\n\t\tres = 2 * self.mySqrt(x / 4)\n\t\tif (res + 1) * (res + 1) <= x and (res + 1) * (res + 1) >= 0:\n\t\t\treturn res + 1\n\t\treturn res\n# %%\ns = Solution()\nprint(s.mySqrt(4))", + "status": 1, + "keywords": "数学,二分查找", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/68/68_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/68/68_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/68/68_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/69.json b/data_backup/leetcode/69.json new file mode 100644 index 000000000..69ca4b4c3 --- /dev/null +++ b/data_backup/leetcode/69.json @@ -0,0 +1,24 @@ +{ + "question_id": 70, + "question_title": "爬楼梯", + "difficulty": "简单", + "question_content": "

    假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

    每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?

    注意:给定 n 是一个正整数。

    示例 1:

    输入: 2
    输出:
    2
    解释:
    有两种方法可以爬到楼顶。1. 1 阶 + 1 阶2. 2 阶

    示例 2:

    输入: 3
    输出:
    3
    解释:
    有三种方法可以爬到楼顶。1. 1 阶 + 1 阶 + 1 阶2. 1 阶 + 2 阶3. 2 阶 + 1 阶
    ", + "topic_link": "https://bbs.csdn.net/topics/600470125", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint climbStairs(int n)\n\t{\n\t\tint a = 1;\n\t\tint b = 2;\n\t\tint c = 0;\n\t\tfor (int i = 3; i <= n; i++)\n\t\t{\n\t\t\tc = a + b;\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t}\n\t\treturn n == 1 ? a : (n == 2 ? b : c);\n\t}\n};", + "java": "class Solution {\n\tpublic int climbStairs(int n) {\n\t\tint[] num = new int[n + 1];\n\t\tnum[0] = 1;\n\t\tnum[1] = 1;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tnum[i] = num[i - 1] + num[i - 2];\n\t\t}\n\t\treturn num[n];\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef climbStairs(self, n):\n\t\tif n <= 1:\n\t\t\treturn 1\n\t\tdp = [1] * 2\n\t\tfor i in range(2, n + 1):\n\t\t\tdp[1], dp[0] = dp[1] + dp[0], dp[1]\n\t\treturn dp[1]\n# %%\ns = Solution()\nprint(s.climbStairs(2))", + "status": 1, + "keywords": "记忆化搜索,数学,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/69/69_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/69/69_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/69/69_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/7.json b/data_backup/leetcode/7.json new file mode 100644 index 000000000..6c3509731 --- /dev/null +++ b/data_backup/leetcode/7.json @@ -0,0 +1,24 @@ +{ + "question_id": 8, + "question_title": "字符串转换整数 (atoi)", + "difficulty": "中等", + "question_content": "
    \n\t

    请你来实现一个 myAtoi(string s) 函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的 atoi 函数)。

    \n\n\t

    函数 myAtoi(string s) 的算法如下:

    \n\n\t
      \n\t\t
    • 读入字符串并丢弃无用的前导空格
    • \n\t\t
    • 检查下一个字符(假设还未到字符末尾)为正还是负号,读取该字符(如果有)。 确定最终结果是负数还是正数。 如果两者都不存在,则假定结果为正。
    • \n\t\t
    • 读入下一个字符,直到到达下一个非数字字符或到达输入的结尾。字符串的其余部分将被忽略。
    • \n\t\t
    • 将前面步骤读入的这些数字转换为整数(即,\"123\" -> 123, \"0032\" -> 32)。如果没有读入数字,则整数为 0 。必要时更改符号(从步骤 2 开始)。
    • \n\t\t
    • 如果整数数超过 32 位有符号整数范围 [−231,  231 − 1]\n\t\t\t,需要截断这个整数,使其保持在这个范围内。具体来说,小于 −231 的整数应该被固定为 −231 ,大于\n\t\t\t231 − 1 的整数应该被固定为 231 − 1 。\n\t\t
    • \n\t\t
    • 返回整数作为最终结果。
    • \n\t
    \n\n\t

    注意:

    \n\n\t
      \n\t\t
    • 本题中的空白字符只包括空格字符 ' '
    • \n\t\t
    • 除前导空格或数字后的其余字符串外,请勿忽略 任何其他字符。
    • \n\t
    \n\n\t

     

    \n\n\t

    示例 1:

    \n\n\t
    输入:s = \"42\"\n输出:42\n解释:加粗的字符串为已经读入的字符,插入符号是当前读取的字符。\n第 1 步:\"42\"(当前没有读入字符,因为没有前导空格)\n\t\t ^\n第 2 步:\"42\"(当前没有读入字符,因为这里不存在 '-' 或者 '+')\n\t\t ^\n第 3 步:\"42\"(读入 \"42\")\n\t\t   ^\n解析得到整数 42 。\n由于 \"42\" 在范围 [-231, 231 - 1] 内,最终结果为 42 。
    \n\n\t

    示例 2:

    \n\n\t
    输入:s = \"   -42\"\n输出:-42\n解释:\n第 1 步:\"   -42\"(读入前导空格,但忽视掉)\n\t\t\t^\n第 2 步:\"   -42\"(读入 '-' 字符,所以结果应该是负数)\n\t\t\t ^\n第 3 步:\"   -42\"(读入 \"42\")\n\t\t\t   ^\n解析得到整数 -42 。\n由于 \"-42\" 在范围 [-231, 231 - 1] 内,最终结果为 -42 。\n
    \n\n\t

    示例 3:

    \n\n\t
    输入:s = \"4193 with words\"\n输出:4193\n解释:\n第 1 步:\"4193 with words\"(当前没有读入字符,因为没有前导空格)\n\t\t ^\n第 2 步:\"4193 with words\"(当前没有读入字符,因为这里不存在 '-' 或者 '+')\n\t\t ^\n第 3 步:\"4193 with words\"(读入 \"4193\";由于下一个字符不是一个数字,所以读入停止)\n\t\t     ^\n解析得到整数 4193 。\n由于 \"4193\" 在范围 [-231, 231 - 1] 内,最终结果为 4193 。\n
    \n\n\t

    示例 4:

    \n\n\t
    输入:s = \"words and 987\"\n输出:0\n解释:\n第 1 步:\"words and 987\"(当前没有读入字符,因为没有前导空格)\n\t\t ^\n第 2 步:\"words and 987\"(当前没有读入字符,因为这里不存在 '-' 或者 '+')\n\t\t ^\n第 3 步:\"words and 987\"(由于当前字符 'w' 不是一个数字,所以读入停止)\n\t\t ^\n解析得到整数 0 ,因为没有读入任何数字。\n由于 0 在范围 [-231, 231 - 1] 内,最终结果为 0 。
    \n\n\t

    示例 5:

    \n\n\t
    输入:s = \"-91283472332\"\n输出:-2147483648\n解释:\n第 1 步:\"-91283472332\"(当前没有读入字符,因为没有前导空格)\n\t\t ^\n第 2 步:\"-91283472332\"(读入 '-' 字符,所以结果应该是负数)\n\t\t  ^\n第 3 步:\"-91283472332\"(读入 \"91283472332\")\n\t\t            ^\n解析得到整数 -91283472332 。\n由于 -91283472332 小于范围 [-231, 231 - 1] 的下界,最终结果被截断为 -231 = -2147483648 。
    \n\n\t

     

    \n\n\t

    提示:

    \n\n\t
      \n\t\t
    • 0 <= s.length <= 200
    • \n\t\t
    • s 由英文字母(大写和小写)、数字(0-9)、' ''+''-' 和\n\t\t\t'.' 组成\n\t\t
    • \n\t
    \n
    ", + "topic_link": "https://bbs.csdn.net/topics/600470794", + "cpp": "int myAtoi(char *str)\n{\n\tint i = 0;\n\tint sign = 0;\n\twhile (str[i] && str[i] == ' ')\n\t\ti++;\n\tif (str[i] == NULL)\n\t\treturn 0;\n\tif (str[i] == '-')\n\t{\n\t\tsign = 1;\n\t\ti++;\n\t}\n\telse if (str[i] == '+')\n\t{\n\t\tsign = 0;\n\t\ti++;\n\t}\n\telse if (str[i] < '0')\n\t\treturn 0;\n\telse if (str[i] > '9')\n\t\treturn 0;\n\tlong long int r = 0;\n\twhile (str[i])\n\t{\n\t\tif (str[i] < '0')\n\t\t\tbreak;\n\t\telse if (str[i] > '9')\n\t\t\tbreak;\n\t\telse\n\t\t\tr = r * 10 + str[i++] - '0';\n\t\tif (r > INT_MAX)\n\t\t\tbreak;\n\t}\n\tr = sign ? -r : r;\n\tif (r < INT_MIN)\n\t\treturn INT_MIN;\n\tif (r > INT_MAX)\n\t\treturn INT_MAX;\n\treturn (int)r;\n}", + "java": "class Solution {\n\tpublic int myAtoi(String s) {\n\t\tlong y = 0;\n\t\tint i = 0;\n\t\tboolean w = false;\n\t\tboolean sign = false;\n\t\tint offset = 0;\n\t\tchar[] ints = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };\n\t\twhile (i < s.length()) {\n\t\t\tchar c = s.charAt(i);\n\t\t\tboolean isSign = false;\n\t\t\tif (w == false && c != ' ') {\n\t\t\t\tw = true;\n\t\t\t\tif (c == '-') {\n\t\t\t\t\tsign = true;\n\t\t\t\t\tisSign = true;\n\t\t\t\t}\n\t\t\t\tif (c == '+') {\n\t\t\t\t\tisSign = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (w && (!isSign)) {\n\t\t\t\tint v = Arrays.binarySearch(ints, c);\n\t\t\t\tif (v < 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ty = y * 10 + v;\n\t\t\t\tif (y > 0x7FFFFFFF) {\n\t\t\t\t\ty = 0x7FFFFFFF;\n\t\t\t\t\toffset = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\treturn sign ? -(int) (y + offset) : (int) y;\n\t}\n}", + "js": "/**\n * @param {string} str\n * @return {number}\n */\nvar myAtoi = function(str) {\n let y=0;\n let i=0;\n let w=false;\n let sign=false;\n const ints=['0','1','2','3','4','5','6','7','8','9'];\n while(i0x7FFFFFFF){\n \ty = 0x7FFFFFFF;\n offset = 1;\n }\n return sign ? -(y+offset) : y;\n};\n\nfunction main(){\n\n}\n\nmain();\n", + "python": "class Solution:\n\tdef myAtoi(self, s: str) -> int:\n\t\ty = 0\n\t\ti = 0\n\t\tw = False\n\t\tsign = False\n\t\tints = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n\t\twhile i < len(s):\n\t\t\tc = s[i]\n\t\t\tisSign = False\n\t\t\tif w == False and c != ' ':\n\t\t\t\tw = True\n\t\t\t\tif c == '-':\n\t\t\t\t\tsign = True\n\t\t\t\t\tisSign = True\n\t\t\t\tif c == '+':\n\t\t\t\t\tisSign = True\n\t\t\tif w and not isSign:\n\t\t\t\ttry:\n\t\t\t\t\tv = ints.index(c)\n\t\t\t\t\ty = y*10+v\n\t\t\t\texcept:\n\t\t\t\t\tbreak\n\t\t\ti += 1\n\t\toffset = 0\n\t\tif y > 2147483647:\n\t\t\ty = 2147483647\n\t\t\toffset = 1\n\t\treturn -(y+offset) if sign else y\n# %%\ns = Solution()\nprint(s.myAtoi(s = \"42\"))", + "status": 1, + "keywords": "字符串", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/7/7_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/7/7_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/7/7_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/70.json b/data_backup/leetcode/70.json new file mode 100644 index 000000000..d12865c2f --- /dev/null +++ b/data_backup/leetcode/70.json @@ -0,0 +1,24 @@ +{ + "question_id": 71, + "question_title": "简化路径", + "difficulty": "中等", + "question_content": "

    给你一个字符串 path ,表示指向某一文件或目录的 Unix 风格 绝对路径 (以 '/' 开头),请你将其转化为更加简洁的规范路径。

    在 Unix 风格的文件系统中,一个点(.)表示当前目录本身;此外,两个点 (..) 表示将目录切换到上一级(指向父目录);两者都可以是复杂相对路径的组成部分。任意多个连续的斜杠(即,'//')都被视为单个斜杠 '/' 。 对于此问题,任何其他格式的点(例如,'...')均被视为文件/目录名称。

    请注意,返回的 规范路径 必须遵循下述格式:

      \t
    • 始终以斜杠 '/' 开头。
    • \t
    • 两个目录名之间必须只有一个斜杠 '/'
    • \t
    • 最后一个目录名(如果存在)不能 '/' 结尾。
    • \t
    • 此外,路径仅包含从根目录到目标文件或目录的路径上的目录(即,不含 '.''..')。

    返回简化后得到的 规范路径

     

    示例 1:

    输入:path = \"/home/\"
    输出:
    \"/home\"
    解释:
    注意,最后一个目录名后面没有斜杠。

    示例 2:

    输入:path = \"/../\"
    输出:
    \"/\"
    解释:
    从根目录向上一级是不可行的,因为根目录是你可以到达的最高级。

    示例 3:

    输入:path = \"/home//foo/\"
    输出:
    \"/home/foo\"
    解释:
    在规范路径中,多个连续斜杠需要用一个斜杠替换。

    示例 4:

    输入:path = \"/a/./b/../../c/\"
    输出:
    \"/c\"

     

    提示:

      \t
    • 1 <= path.length <= 3000
    • \t
    • path 由英文字母,数字,'.''/''_' 组成。
    • \t
    • path 是一个有效的 Unix 风格绝对路径。
    ", + "topic_link": "https://bbs.csdn.net/topics/600470830", + "cpp": "#include \n#include \n#include \nstatic char *simplifyPath(char *path)\n{\n\tint len = strlen(path);\n\tif (len == 0)\n\t{\n\t\treturn path;\n\t}\n\tchar *p = path;\n\tint *indexes = malloc(len * sizeof(int));\n\tint depth = 0;\n\tint name_start = 1;\n\twhile (*p != '\\0')\n\t{\n\t\tif (*p == '/')\n\t\t{\n\t\t\tif (p > path && *(p - 1) != '/' && *(p - 1) != '.')\n\t\t\t{\n\t\t\t\tname_start = 1;\n\t\t\t}\n\t\t}\n\t\telse if (*p == '.')\n\t\t{\n\t\t\tif (*(p + 1) == '\\0' || *(p + 1) == '/')\n\t\t\t{\n\t\t\t\tp += 1;\n\t\t\t}\n\t\t\telse if (*(p + 1) == '.' && (*(p + 2) == '\\0' || *(p + 2) == '/'))\n\t\t\t{\n\t\t\t\tif (depth > 0)\n\t\t\t\t{\n\t\t\t\t\tdepth--;\n\t\t\t\t\tname_start = 1;\n\t\t\t\t}\n\t\t\t\tp += 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tindexes[depth++] = p - path;\n\t\t\t\twhile (*p != '/' && *p != '\\0')\n\t\t\t\t{\n\t\t\t\t\tp++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (*p == '\\0')\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (name_start && depth >= 0)\n\t\t\t{\n\t\t\t\tindexes[depth++] = p - path;\n\t\t\t\tname_start = 0;\n\t\t\t}\n\t\t}\n\t\tp++;\n\t}\n\tint i;\n\tchar *result = malloc(len + 1);\n\tchar *q = result;\n\tif (depth <= 0)\n\t{\n\t\t*q++ = '/';\n\t}\n\telse\n\t{\n\t\tfor (i = 0; i < depth; i++)\n\t\t{\n\t\t\tp = path + indexes[i];\n\t\t\t*q++ = '/';\n\t\t\twhile (*p != '/')\n\t\t\t{\n\t\t\t\t*q++ = *p++;\n\t\t\t}\n\t\t}\n\t}\n\t*q = '\\0';\n\treturn result;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test path\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", simplifyPath(argv[1]));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic String simplifyPath(String path) {\n\n\t\tDeque stack = new ArrayDeque<>();\n\n\t\tfor (String str : path.split(\"/\")) {\n\n\t\t\tif (\"\".equals(str) || \".\".equals(str))\n\t\t\t\tcontinue;\n\t\t\tstack.push(str);\n\t\t}\n\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint count = 0;\n\t\twhile (!stack.isEmpty()) {\n\t\t\tString str = stack.pop();\n\n\t\t\tif (\"..\".equals(str))\n\t\t\t\tcount++;\n\t\t\telse {\n\n\t\t\t\tif (count > 0) {\n\t\t\t\t\tcount--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tsb.insert(0, str);\n\t\t\t\tsb.insert(0, \"/\");\n\t\t\t}\n\t\t}\n\n\t\tif (sb.length() == 0)\n\t\t\tsb.append(\"/\");\n\n\t\treturn sb.toString();\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef simplifyPath(self, path):\n\t\t\"\"\"\n\t\t:type path: str\n\t\t:rtype: str\n\t\t\"\"\"\n\t\tresult = []\n\t\tplist = path.split('/')\n\t\tfor pos in plist:\n\t\t\tif pos:\n\t\t\t\tif pos == '..':\n\t\t\t\t\ttry:\n\t\t\t\t\t\tresult.pop()\n\t\t\t\t\texcept:\n\t\t\t\t\t\tresult = []\n\t\t\t\telif pos != '.':\n\t\t\t\t\tresult.append(pos)\n\t\treturn '/'+'/'.join(result)\n# %%\ns = Solution()\nprint(s.simplifyPath(path = \"/home/\"))", + "status": 1, + "keywords": "栈,字符串", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/cmqwan/article/details/85017341" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/70/70_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/70/70_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/70/70_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/71.json b/data_backup/leetcode/71.json new file mode 100644 index 000000000..52699bb6b --- /dev/null +++ b/data_backup/leetcode/71.json @@ -0,0 +1,24 @@ +{ + "question_id": 72, + "question_title": "编辑距离", + "difficulty": "困难", + "question_content": "

    给你两个单词 word1 和 word2,请你计算出将 word1 转换成 word2 所使用的最少操作数 。

    你可以对一个单词进行如下三种操作:

      \t
    • 插入一个字符
    • \t
    • 删除一个字符
    • \t
    • 替换一个字符

     

    示例 1:

    输入:word1 = \"horse\", word2 = \"ros\"
    输出:
    3
    解释:
    horse -> rorse (将 'h' 替换为 'r')rorse -> rose (删除 'r')rose -> ros (删除 'e')

    示例 2:

    输入:word1 = \"intention\", word2 = \"execution\"
    输出:
    5
    解释:
    intention -> inention (删除 't')inention -> enention (将 'i' 替换为 'e')enention -> exention (将 'n' 替换为 'x')exention -> exection (将 'n' 替换为 'c')exection -> execution (插入 'u')

     

    提示:

      \t
    • 0 <= word1.length, word2.length <= 500
    • \t
    • word1word2 由小写英文字母组成
    ", + "topic_link": "https://bbs.csdn.net/topics/600470829", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint minDistance(string word1, string word2)\n\t{\n\t\tint l1 = word1.length();\n\t\tint l2 = word2.length();\n\t\tvector dp(l2 + 1);\n\t\tfor (int i = 0; i <= l2; i++)\n\t\t{\n\t\t\tdp[i] = i;\n\t\t}\n\t\tint up = 0;\n\t\tfor (int i = 1; i <= l1; i++)\n\t\t{\n\t\t\tint left_up = dp[0];\n\t\t\tdp[0] = i;\n\t\t\tfor (int j = 1; j <= l2; j++)\n\t\t\t{\n\t\t\t\tup = dp[j];\n\t\t\t\tif (word1[i - 1] == word2[j - 1])\n\t\t\t\t{\n\t\t\t\t\tdp[j] = left_up;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tdp[j] = 1 + min(left_up, min(up, dp[j - 1]));\n\t\t\t\t}\n\t\t\t\tleft_up = up;\n\t\t\t}\n\t\t}\n\t\treturn dp[l2];\n\t}\n};", + "java": "class Solution {\n\tpublic int minDistance(String word1, String word2) {\n\t\tint len1 = word1.length();\n\t\tint len2 = word2.length();\n\n\t\tif (len1 * len2 == 0)\n\t\t\treturn len1 + len2;\n\t\tString longerStr = len1 > len2 ? word1 : word2;\n\t\tString shorterStr = len1 > len2 ? word2 : word1;\n\t\tint shorterOne = Math.min(len1, len2);\n\n\t\tint[] dp = new int[shorterOne + 1];\n\n\t\tfor (int i = 0; i < shorterOne + 1; i++) {\n\t\t\tdp[i] = i;\n\t\t}\n\n\t\tfor (int j = 1; j <= longerStr.length(); j++) {\n\n\t\t\tint left = j;\n\n\t\t\tfor (int i = 1; i <= shorterStr.length(); i++) {\n\t\t\t\tint updateDown = dp[i] + 1;\n\t\t\t\tint updateLeft = left + 1;\n\t\t\t\tint updateLeftDown = dp[i - 1];\n\n\t\t\t\tif (longerStr.charAt(j - 1) != shorterStr.charAt(i - 1)) {\n\t\t\t\t\tupdateLeftDown++;\n\t\t\t\t}\n\n\t\t\t\tint min = Math.min(updateLeft, Math.min(updateDown, updateLeftDown));\n\n\t\t\t\tdp[i - 1] = left;\n\n\t\t\t\tif (i == dp.length - 1) {\n\t\t\t\t\tdp[i] = min;\n\t\t\t\t} else {\n\n\t\t\t\t\tleft = min;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[shorterOne];\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef minDistance(self, word1, word2):\n\t\tls_1, ls_2 = len(word1), len(word2)\n\t\tdp = list(range(ls_1 + 1))\n\t\tfor j in range(1, ls_2 + 1):\n\t\t\tpre = dp[0]\n\t\t\tdp[0] = j\n\t\t\tfor i in range(1, ls_1 + 1):\n\t\t\t\ttemp = dp[i]\n\t\t\t\tif word1[i - 1] == word2[j - 1]:\n\t\t\t\t\tdp[i] = pre\n\t\t\t\telse:\n\t\t\t\t\tdp[i] = min(pre + 1, dp[i] + 1, dp[i - 1] + 1)\n\t\t\t\tpre = temp\n\t\treturn dp[ls_1]\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.minDistance(\"horse\",\"ros\"))\t\t\n\tprint (s.minDistance(\"intention\",\"execution\"))\t\t", + "status": 1, + "keywords": "字符串,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/71/71_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/71/71_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/71/71_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/72.json b/data_backup/leetcode/72.json new file mode 100644 index 000000000..849e1c1e6 --- /dev/null +++ b/data_backup/leetcode/72.json @@ -0,0 +1,24 @@ +{ + "question_id": 73, + "question_title": "矩阵置零", + "difficulty": "中等", + "question_content": "

    给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 。请使用 原地 算法

    进阶:

      \t
    • 一个直观的解决方案是使用  O(mn) 的额外空间,但这并不是一个好的解决方案。
    • \t
    • 一个简单的改进方案是使用 O(m + n) 的额外空间,但这仍然不是最好的解决方案。
    • \t
    • 你能想出一个仅使用常量空间的解决方案吗?

     

    示例 1:

    \"\"
    输入:matrix = [[1,1,1],[1,0,1],[1,1,1]]
    输出:
    [[1,0,1],[0,0,0],[1,0,1]]

    示例 2:

    \"\"
    输入:matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
    输出:
    [[0,0,0,0],[0,4,5,0],[0,3,1,0]]

     

    提示:

      \t
    • m == matrix.length
    • \t
    • n == matrix[0].length
    • \t
    • 1 <= m, n <= 200
    • \t
    • -231 <= matrix[i][j] <= 231 - 1
    ", + "topic_link": "https://bbs.csdn.net/topics/600470228", + "cpp": "#include \nusing namespace std;\npublic:\nvoid setZeroes(vector> &matrix)\n{\n\tbool bRow = false, bCol = false;\n\tfor (int row = 0; row < matrix.size(); row++)\n\t{\n\t\tfor (int col = 0; col < matrix[row].size(); col++)\n\t\t{\n\t\t\tif (matrix[row][col] == 0)\n\t\t\t{\n\t\t\t\tif (row == 0)\n\t\t\t\t{\n\t\t\t\t\tbRow = true;\n\t\t\t\t}\n\t\t\t\tif (col == 0)\n\t\t\t\t{\n\t\t\t\t\tbCol = true;\n\t\t\t\t}\n\t\t\t\tmatrix[0][col] = matrix[row][0] = 0;\n\t\t\t}\n\t\t}\n\t}\n\tfor (int row = 1; row < matrix.size(); row++)\n\t{\n\t\tfor (int col = 1; col < matrix[row].size(); col++)\n\t\t{\n\t\t\tif (matrix[0][col] == 0 || matrix[row][0] == 0)\n\t\t\t{\n\t\t\t\tmatrix[row][col] = 0;\n\t\t\t}\n\t\t}\n\t}\n\tif (bRow)\n\t{\n\t\tfor (auto &m : matrix[0])\n\t\t{\n\t\t\tm = 0;\n\t\t}\n\t}\n\tif (bCol)\n\t{\n\t\tfor (int row = 0; row < matrix.size(); row++)\n\t\t{\n\t\t\tmatrix[row][0] = 0;\n\t\t}\n\t}\n}\n}\n;", + "java": "class Solution {\n\tpublic void setZeroes(int[][] matrix) {\n\t\tint[] xNum = new int[matrix[0].length];\n\t\tint[] yNum = new int[matrix.length];\n\t\tfor (int i = 0; i < matrix.length; i++) {\n\t\t\tfor (int j = 0; j < matrix[i].length; j++) {\n\t\t\t\tif (matrix[i][j] == 0) {\n\t\t\t\t\txNum[j] = 1;\n\t\t\t\t\tyNum[i] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < matrix.length; i++) {\n\t\t\tfor (int j = 0; j < matrix[i].length; j++) {\n\t\t\t\tif (xNum[j] == 1 || yNum[i] == 1) {\n\t\t\t\t\tmatrix[i][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef setZeroes(self, matrix):\n\t\t\"\"\"\n\t\t:type matrix: List[List[int]]\n\t\t:rtype: void Do not return anything, modify matrix in-place instead.\n\t\t\"\"\"\n\t\tif not matrix:\n\t\t\treturn\n\t\tm = len(matrix)\n\t\tif m == 0:\n\t\t\treturn\n\t\tr = []\n\t\tc = []\n\t\tn = len(matrix[0])\n\t\tfor i in range(m):\n\t\t\tfor j in range(n):\n\t\t\t\tif matrix[i][j] == 0:\n\t\t\t\t\tr.append(i)\n\t\t\t\t\tc.append(j)\n\t\tr = set(r)\n\t\tc = set(c)\n\t\tfor i in r:\n\t\t\tfor j in range(n):\n\t\t\t\tmatrix[i][j] = 0\n\t\tfor i in range(m):\n\t\t\tfor j in c:\n\t\t\t\tmatrix[i][j] = 0\n\t\treturn matrix\n# %%\ns = Solution()\nprint(s.setZeroes(matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]))", + "status": 1, + "keywords": "数组,哈希表,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104343739" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/72/72_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/72/72_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/72/72_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/73.json b/data_backup/leetcode/73.json new file mode 100644 index 000000000..b2b152a64 --- /dev/null +++ b/data_backup/leetcode/73.json @@ -0,0 +1,24 @@ +{ + "question_id": 74, + "question_title": "搜索二维矩阵", + "difficulty": "中等", + "question_content": "

    编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:

      \t
    • 每行中的整数从左到右按升序排列。
    • \t
    • 每行的第一个整数大于前一行的最后一个整数。

     

    示例 1:

    \"\"
    输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
    输出:
    true

    示例 2:

    \"\"
    输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
    输出:
    false

     

    提示:

      \t
    • m == matrix.length
    • \t
    • n == matrix[i].length
    • \t
    • 1 <= m, n <= 100
    • \t
    • -104 <= matrix[i][j], target <= 104
    ", + "topic_link": "https://bbs.csdn.net/topics/600469923", + "cpp": "#include \n#include \n#include \nstatic int binary_search(int *nums, int len, int target)\n{\n\tint low = -1;\n\tint high = len;\n\twhile (low + 1 < high)\n\t{\n\t\tint mid = low + (high - low) / 2;\n\t\tif (target > nums[mid])\n\t\t{\n\t\t\tlow = mid;\n\t\t}\n\t\telse\n\t\t{\n\t\t\thigh = mid;\n\t\t}\n\t}\n\tif (high == len || nums[high] != target)\n\t{\n\t\treturn -high - 1;\n\t}\n\telse\n\t{\n\t\treturn high;\n\t}\n}\nstatic bool searchMatrix(int **matrix, int matrixRowSize, int matrixColSize, int target)\n{\n\tif (matrixRowSize == 0 || matrixColSize == 0)\n\t{\n\t\treturn false;\n\t}\n\tif (target < matrix[0][0] || target > matrix[matrixRowSize - 1][matrixColSize - 1])\n\t{\n\t\treturn false;\n\t}\n\tint row = 0;\n\tint *nums = NULL;\n\tif (matrixRowSize > 0)\n\t{\n\t\tnums = malloc(matrixRowSize * sizeof(int));\n\t\tfor (row = 0; row < matrixRowSize; row++)\n\t\t{\n\t\t\tnums[row] = matrix[row][0];\n\t\t}\n\t\trow = binary_search(nums, matrixRowSize, target);\n\t\tif (row >= 0)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\trow = -row - 1;\n\t\t\tif (row == 0)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\trow--;\n\t\t\t}\n\t\t}\n\t}\n\tint col = binary_search(matrix[row], matrixColSize, target);\n\treturn col >= 0;\n}\nint main(int argc, char **argv)\n{\n\tint row = 3;\n\tint col = 4;\n\tint **mat = malloc(row * sizeof(int *));\n\tmat[0] = malloc(col * sizeof(int));\n\tmat[0][0] = 1;\n\tmat[0][1] = 3;\n\tmat[0][2] = 5;\n\tmat[0][3] = 7;\n\tmat[1] = malloc(col * sizeof(int));\n\tmat[1][0] = 10;\n\tmat[1][1] = 11;\n\tmat[1][2] = 16;\n\tmat[1][3] = 20;\n\tmat[2] = malloc(col * sizeof(int));\n\tmat[2][0] = 23;\n\tmat[2][1] = 30;\n\tmat[2][2] = 34;\n\tmat[2][3] = 50;\n\tprintf(\"%s\\n\", searchMatrix(mat, row, col, atoi(argv[1])) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean searchMatrix(int[][] matrix, int target) {\n\t\tif (matrix.length == 0 || matrix[0].length == 0)\n\t\t\treturn false;\n\t\tint begin, mid, end;\n\t\tbegin = mid = 0;\n\t\tint len1 = matrix.length, len2 = matrix[0].length;\n\t\tend = len1 * len2 - 1;\n\t\twhile (begin < end) {\n\t\t\tmid = (begin + end) / 2;\n\t\t\tif (matrix[mid / len2][mid % len2] < target)\n\t\t\t\tbegin = mid + 1;\n\t\t\telse\n\t\t\t\tend = mid;\n\t\t}\n\t\treturn matrix[begin / len2][begin % len2] == target;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef searchMatrix(self, matrix, target):\n\t\t\"\"\"\n\t\t:type matrix: List[List[int]]\n\t\t:type target: int\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\tif not matrix or not matrix[0]:\n\t\t\treturn False\n\t\trows = len(matrix)\n\t\tcols = len(matrix[0])\n\t\trow, col = 0, cols - 1\n\t\twhile True:\n\t\t\tif row < rows and col >= 0:\n\t\t\t\tif matrix[row][col] == target:\n\t\t\t\t\treturn True\n\t\t\t\telif matrix[row][col] < target:\n\t\t\t\t\trow += 1\n\t\t\t\telse:\n\t\t\t\t\tcol -= 1\n\t\t\telse:\n\t\t\t\treturn False\n# %%\ns = Solution()\nprint(s.searchMatrix(matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3))", + "status": 1, + "keywords": "数组,二分查找,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104343847" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/73/73_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/73/73_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/73/73_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/74.json b/data_backup/leetcode/74.json new file mode 100644 index 000000000..449a4e7e1 --- /dev/null +++ b/data_backup/leetcode/74.json @@ -0,0 +1,24 @@ +{ + "question_id": 75, + "question_title": "颜色分类", + "difficulty": "中等", + "question_content": "

    给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。

    此题中,我们使用整数 0、 12 分别表示红色、白色和蓝色。

       

      示例 1:

      输入:nums = [2,0,2,1,1,0]
      输出:
      [0,0,1,1,2,2]

      示例 2:

      输入:nums = [2,0,1]
      输出:
      [0,1,2]

      示例 3:

      输入:nums = [0]
      输出:
      [0]

      示例 4:

      输入:nums = [1]
      输出:
      [1]

       

      提示:

        \t
      • n == nums.length
      • \t
      • 1 <= n <= 300
      • \t
      • nums[i]012

       

      进阶:

        \t
      • 你可以不使用代码库中的排序函数来解决这道题吗?
      • \t
      • 你能想出一个仅使用常数空间的一趟扫描算法吗?
      ", + "topic_link": "https://bbs.csdn.net/topics/600470126", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvoid sortColors(vector &nums)\n\t{\n\t\tint i = 0, j = nums.size() - 1;\n\t\twhile (i < j)\n\t\t{\n\t\t\tif (nums[i] == 0)\n\t\t\t{\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (nums[j] != 0)\n\t\t\t{\n\t\t\t\tj--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tswap(nums[i], nums[j]);\n\t\t}\n\t\tj = nums.size() - 1;\n\t\twhile (i < j)\n\t\t{\n\t\t\tif (nums[i] == 1)\n\t\t\t{\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (nums[j] != 1)\n\t\t\t{\n\t\t\t\tj--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tswap(nums[i], nums[j]);\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic void sortColors(int[] nums) {\n\t\tint low = 0, high = nums.length - 1;\n\t\tint i = 0;\n\t\twhile (i <= high) {\n\t\t\tif (nums[i] == 0) {\n\t\t\t\tint tmp = nums[i];\n\t\t\t\tnums[i] = nums[low];\n\t\t\t\tnums[low] = tmp;\n\t\t\t\t++low;\n\t\t\t\t++i;\n\t\t\t} else if (nums[i] == 1) {\n\t\t\t\t++i;\n\t\t\t} else if (i <= high && nums[i] == 2) {\n\t\t\t\tint tmp = nums[i];\n\t\t\t\tnums[i] = nums[high];\n\t\t\t\tnums[high] = tmp;\n\t\t\t\t--high;\n\t\t\t}\n\t\t}\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef sortColors(self, nums):\n\t\tlow, mid, high = 0, 0, len(nums) - 1\n\t\twhile mid <= high:\n\t\t\tif nums[mid] == 0:\n\t\t\t\tnums[low], nums[mid] = nums[mid], nums[low]\n\t\t\t\tlow += 1\n\t\t\t\tmid += 1\n\t\t\telif nums[mid] == 1:\n\t\t\t\tmid += 1\n\t\t\telse:\n\t\t\t\tnums[high], nums[mid] = nums[mid], nums[high]\n\t\t\t\thigh -= 1\n\t\treturn nums\n# %%\ns = Solution()\nprint(s.sortColors(nums = [2,0,2,1,1,0]))", + "status": 1, + "keywords": "数组,双指针,排序", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104343861" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/74/74_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/74/74_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/74/74_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/75.json b/data_backup/leetcode/75.json new file mode 100644 index 000000000..4f33b4b08 --- /dev/null +++ b/data_backup/leetcode/75.json @@ -0,0 +1,24 @@ +{ + "question_id": 76, + "question_title": "最小覆盖子串", + "difficulty": "困难", + "question_content": "

      给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 \"\"

      注意:如果 s 中存在这样的子串,我们保证它是唯一的答案。

       

      示例 1:

      输入:s = \"ADOBECODEBANC\", t = \"ABC\"
      输出:
      \"BANC\"

      示例 2:

      输入:s = \"a\", t = \"a\"
      输出:
      \"a\"

       

      提示:

        \t
      • 1 <= s.length, t.length <= 105
      • \t
      • st 由英文字母组成

       

      进阶:你能设计一个在 o(n) 时间内解决此问题的算法吗?", + "topic_link": "https://bbs.csdn.net/topics/600471015", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tstring minWindow(string s, string t)\n\t{\n\t\tvector count(128);\n\t\tfor (char c : t)\n\t\t{\n\t\t\tcount[c]++;\n\t\t}\n\t\tint l = 0, r = 0;\n\t\tint need_to_meet = t.length();\n\t\tint start, min_len = INT_MAX;\n\t\twhile (r < s.length())\n\t\t{\n\t\t\tif (--count[s[r++]] >= 0)\n\t\t\t{\n\t\t\t\tneed_to_meet--;\n\t\t\t}\n\t\t\twhile (need_to_meet == 0)\n\t\t\t{\n\t\t\t\tif (r - l < min_len)\n\t\t\t\t{\n\t\t\t\t\tstart = l;\n\t\t\t\t\tmin_len = r - l;\n\t\t\t\t}\n\t\t\t\tif (++count[s[l++]] > 0)\n\t\t\t\t{\n\t\t\t\t\tneed_to_meet++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn min_len == INT_MAX ? \"\" : s.substr(start, min_len);\n\t}\n};", + "java": "public class Min_Win_Sub {\n\tpublic String minWindow(String s, String t) {\n\t\tint[] ta = new int[128];\n\t\tint[] sa = new int[128];\n\t\tint min = Integer.MAX_VALUE;\n\t\tString minwin = \"\";\n\t\tfor (int i = 0; i < t.length(); i++) {\n\t\t\tta[t.charAt(i)]++;\n\t\t}\n\t\tint count = 0;\n\t\tint end = 0;\n\t\tint start = 0;\n\t\twhile (end < s.length()) {\n\t\t\tif (ta[s.charAt(end)] != 0) {\n\t\t\t\tif (sa[s.charAt(end)] < ta[s.charAt(end)]) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tsa[s.charAt(end)]++;\n\t\t\t}\n\t\t\tif (count == t.length()) {\n\t\t\t\twhile (ta[s.charAt(start)] == 0 || sa[s.charAt(start)] > ta[s.charAt(start)]) {\n\t\t\t\t\tif (sa[s.charAt(start)] > ta[s.charAt(start)]) {\n\t\t\t\t\t\tsa[s.charAt(start)]--;\n\t\t\t\t\t}\n\t\t\t\t\tstart++;\n\t\t\t\t}\n\t\t\t\tif (end - start + 1 < min) {\n\t\t\t\t\tminwin = s.substring(start, end + 1);\n\t\t\t\t\tmin = end - start + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tend++;\n\t\t}\n\t\treturn minwin;\n\t}\n\n}", + "js": "", + "python": "class Solution(object):\n\tdef minWindow(self, s, t):\n\t\tls_s, ls_t = len(s), len(t)\n\t\tneed_to_find = [0] * 256\n\t\thas_found = [0] * 256\n\t\tmin_begin, min_end = 0, -1\n\t\tmin_window = 100000000000000\n\t\tfor index in range(ls_t):\n\t\t\tneed_to_find[ord(t[index])] += 1\n\t\tcount, begin = 0, 0\n\t\tfor end in range(ls_s):\n\t\t\tend_index = ord(s[end])\n\t\t\tif need_to_find[end_index] == 0:\n\t\t\t\tcontinue\n\t\t\thas_found[end_index] += 1\n\t\t\tif has_found[end_index] <= need_to_find[end_index]:\n\t\t\t\tcount += 1\n\t\t\tif count == ls_t:\n\t\t\t\tbegin_index = ord(s[begin])\n\t\t\t\twhile need_to_find[begin_index] == 0 or\\\n\t\t\t\t\thas_found[begin_index] > need_to_find[begin_index]:\n\t\t\t\t\tif has_found[begin_index] > need_to_find[begin_index]:\n\t\t\t\t\t\thas_found[begin_index] -= 1\n\t\t\t\t\tbegin += 1\n\t\t\t\t\tbegin_index = ord(s[begin])\n\t\t\t\twindow_ls = end - begin + 1\n\t\t\t\tif window_ls < min_window:\n\t\t\t\t\tmin_begin = begin\n\t\t\t\t\tmin_end = end\n\t\t\t\t\tmin_window = window_ls\n\t\tif count == ls_t:\n\t\t\treturn s[min_begin: min_end + 1]\n\t\telse:\n\t\t\treturn ''\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.minWindow('a', 'a'))", + "status": 1, + "keywords": "哈希表,字符串,滑动窗口", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/75/75_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/75/75_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/75/75_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/76.json b/data_backup/leetcode/76.json new file mode 100644 index 000000000..e7d9c091c --- /dev/null +++ b/data_backup/leetcode/76.json @@ -0,0 +1,24 @@ +{ + "question_id": 77, + "question_title": "组合", + "difficulty": "中等", + "question_content": "

      给定两个整数 nk,返回 1 ... n 中所有可能的 k 个数的组合。

      \n

      示例:

      \n
      输入: n = 4, k = 2
      输出:
      [[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]
      ", + "topic_link": "https://bbs.csdn.net/topics/600470921", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> combine(int n, int k)\n\t{\n\t\tvector> res;\n\t\tdfs(n, k, 1, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(int n, int k, int start, vector> &res)\n\t{\n\t\tif (stack.size() == k)\n\t\t{\n\t\t\tres.push_back(stack);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int i = start; i <= n; i++)\n\t\t\t{\n\t\t\t\tstack.push_back(i);\n\t\t\t\tdfs(n, k, i + 1, res);\n\t\t\t\tstack.pop_back();\n\t\t\t}\n\t\t}\n\t}\n};", + "java": "\nimport java.util.*;\n\npublic class Solution77 {\n\tList> output = new LinkedList<>();\n\tint n;\n\tint k;\n\n\tpublic void traceback(int first, LinkedList current) {\n\t\tif (current.size() == k) {\n\n\t\t\toutput.add(new LinkedList(current));\n\t\t\tSystem.out.println(output);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (int i = first; i <= n; i++) {\n\n\t\t\tcurrent.add(i);\n\t\t\ttraceback(i + 1, current);\n\n\t\t\tcurrent.removeLast();\n\t\t}\n\t}\n\n\tpublic List> combine(int n, int k) {\n\t\tthis.n = n;\n\t\tthis.k = k;\n\t\ttraceback(1, new LinkedList<>());\n\t\treturn output;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef combine(self, n, k):\n\t\tres = []\n\t\tself.get_combine(res, [], n, k, 1)\n\t\treturn res\n\tdef get_combine(self, res, prefix, n, k, start):\n\t\tif k == 0:\n\t\t\tres.append(list(prefix))\n\t\telif start <= n:\n\t\t\tprefix.append(start)\n\t\t\tself.get_combine(res, prefix,\n\t\t\t\t\t\t\t n, k - 1, start + 1)\n\t\t\tprefix.pop()\n\t\t\tself.get_combine(res, prefix,\n\t\t\t\t\t\t\t n, k, start + 1)\nif __name__ == \"__main__\":\n\ts = Solution()\n\tprint (s.combine(4, 2))", + "status": 1, + "keywords": "数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/76/76_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/76/76_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/76/76_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/77.json b/data_backup/leetcode/77.json new file mode 100644 index 000000000..bd385e6c7 --- /dev/null +++ b/data_backup/leetcode/77.json @@ -0,0 +1,24 @@ +{ + "question_id": 78, + "question_title": "子集", + "difficulty": "中等", + "question_content": "

      给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。

      解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。

       

      示例 1:

      输入:nums = [1,2,3]
      输出:
      [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]

      示例 2:

      输入:nums = [0]
      输出:
      [[],[0]]

       

      提示:

        \t
      • 1 <= nums.length <= 10
      • \t
      • -10 <= nums[i] <= 10
      • \t
      • nums 中的所有元素 互不相同
      ", + "topic_link": "https://bbs.csdn.net/topics/600469824", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> subsets(vector &nums)\n\t{\n\t\tvector> res;\n\t\tdfs(nums, 0, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(vector &nums, int start, vector> &res)\n\t{\n\t\tres.push_back(stack);\n\t\tfor (int i = start; i < nums.size(); i++)\n\t\t{\n\t\t\tstack.push_back(nums[i]);\n\t\t\tdfs(nums, i + 1, res);\n\t\t\tstack.pop_back();\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic List> subsets(int[] nums) {\n\t\tList> res = new ArrayList>();\n\t\tList tmp = new ArrayList<>();\n\t\tres.add(tmp);\n\t\tif (nums.length == 0)\n\t\t\treturn res;\n\t\thelper(nums, 0, tmp, res);\n\t\treturn res;\n\t}\n\n\tpublic void helper(int[] nums, int start, List tmp, List> res) {\n\t\tfor (int i = start; i < nums.length; i++) {\n\t\t\ttmp.add(nums[i]);\n\t\t\thelper(nums, i + 1, tmp, res);\n\t\t\tres.add(new ArrayList(tmp));\n\t\t\ttmp.remove(tmp.size() - 1);\n\t\t}\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef subsets(self, nums):\n\t\tnums.sort()\n\t\tres = [[]]\n\t\tfor index in range(len(nums)):\n\t\t\tsize = len(res)\n\t\t\tfor j in range(size):\n\t\t\t\tcurr = list(res[j])\n\t\t\t\tcurr.append(nums[index])\n\t\t\t\tres.append(curr)\n\t\treturn res\nif __name__ == \"__main__\":\n\ts = Solution()\n\tprint (s.subsets([1,2,3]))", + "status": 1, + "keywords": "位运算,数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/77/77_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/77/77_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/77/77_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/78.json b/data_backup/leetcode/78.json new file mode 100644 index 000000000..440e53c9b --- /dev/null +++ b/data_backup/leetcode/78.json @@ -0,0 +1,24 @@ +{ + "question_id": 79, + "question_title": "单词搜索", + "difficulty": "中等", + "question_content": "

      给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false

      单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。

       

      示例 1:

      \"\"
      输入:board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\"
      输出:
      true

      示例 2:

      \"\"
      输入:board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\"
      输出:
      true

      示例 3:

      \"\"
      输入:board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCB\"
      输出:
      false

       

      提示:

        \t
      • m == board.length
      • \t
      • n = board[i].length
      • \t
      • 1 <= m, n <= 6
      • \t
      • 1 <= word.length <= 15
      • \t
      • boardword 仅由大小写英文字母组成

       

      进阶:你可以使用搜索剪枝的技术来优化解决方案,使其在 board 更大的情况下可以更快解决问题?

      ", + "topic_link": "https://bbs.csdn.net/topics/600470927", + "cpp": "#include \n#include \n#include \n#include \nstatic bool dfs(char *word, char **board, bool *used,\n\t\t\t\tint row, int col, int row_size, int col_size)\n{\n\tif (board[row][col] != *word)\n\t{\n\t\treturn false;\n\t}\n\tused[row * col_size + col] = true;\n\tif (*(word + 1) == '\\0')\n\t{\n\t\treturn true;\n\t}\n\tbool result = false;\n\tif (row > 0 && !used[(row - 1) * col_size + col])\n\t{\n\t\tresult = dfs(word + 1, board, used, row - 1, col, row_size, col_size);\n\t}\n\tif (!result && row < row_size - 1 && !used[(row + 1) * col_size + col])\n\t{\n\t\tresult = dfs(word + 1, board, used, row + 1, col, row_size, col_size);\n\t}\n\tif (!result && col > 0 && !used[row * col_size + col - 1])\n\t{\n\t\tresult = dfs(word + 1, board, used, row, col - 1, row_size, col_size);\n\t}\n\tif (!result && col < col_size - 1 && !used[row * col_size + col + 1])\n\t{\n\t\tresult = dfs(word + 1, board, used, row, col + 1, row_size, col_size);\n\t}\n\tused[row * col_size + col] = false;\n\treturn result;\n}\nstatic bool exist(char **board, int boardRowSize, int boardColSize, char *word)\n{\n\tint i, j;\n\tint len = strlen(word);\n\tif (len > boardRowSize * boardColSize)\n\t{\n\t\treturn false;\n\t}\n\tbool *used = malloc(boardRowSize * boardColSize);\n\tfor (i = 0; i < boardRowSize; i++)\n\t{\n\t\tfor (j = 0; j < boardColSize; j++)\n\t\t{\n\t\t\tmemset(used, false, boardRowSize * boardColSize);\n\t\t\tif (dfs(word, board, used, i, j, boardRowSize, boardColSize))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test word row1 row2...\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", exist(argv + 2, argc - 2, strlen(argv[2]), argv[1]) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean exist(char[][] board, String word) {\n\t\tint cl = board.length;\n\t\tint rl = board[0].length;\n\t\tboolean[][] flag = new boolean[cl][rl];\n\t\tfor (int i = 0; i < cl; i++) {\n\t\t\tfor (int j = 0; j < rl; j++) {\n\t\t\t\tif (find(board, word, flag, i, j, 0))\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpublic boolean find(char[][] board, String word, boolean[][] flag, int i, int j, int index) {\n\t\tint cl = board.length;\n\t\tint rl = board[0].length;\n\t\tif (word.length() == index)\n\t\t\treturn true;\n\t\tif (i < 0 || i >= cl || j >= rl || j < 0)\n\t\t\treturn false;\n\t\tif (flag[i][j] || word.charAt(index) != board[i][j])\n\t\t\treturn false;\n\t\tflag[i][j] = true;\n\t\tboolean judge = find(board, word, flag, i - 1, j, index + 1) || find(board, word, flag, i + 1, j, index + 1)\n\t\t\t\t|| find(board, word, flag, i, j - 1, index + 1) || find(board, word, flag, i, j + 1, index + 1);\n\t\tflag[i][j] = false;\n\t\treturn judge;\n\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef exist(self, board, word):\n\t\t\"\"\"\n\t\t:type board: List[List[str]]\n\t\t:type word: str\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\tcheck_board = [[True] * len(board[0]) for _ in range(len(board))]\n\t\tfor i in range(len(board)):\n\t\t\tfor j in range(len(board[0])):\n\t\t\t\tif board[i][j] == word[0] and check_board:\n\t\t\t\t\tcheck_board[i][j] = False\n\t\t\t\t\tres = self.check_exist(check_board, board, word, 1, len(word), i, j)\n\t\t\t\t\tif res:\n\t\t\t\t\t\treturn True\n\t\t\t\t\tcheck_board[i][j] = True\n\t\treturn False\n\tdef check_exist(self, check_board, board, word, index, ls, row, col):\n\t\tif index == ls:\n\t\t\treturn True\n\t\tfor temp in [(0, 1),(0, -1),(1, 0),(-1, 0)]:\n\t\t\tcurr_row = row + temp[0]\n\t\t\tcurr_col = col + temp[1]\n\t\t\tif curr_row >= 0 and curr_row < len(board) and curr_col >= 0 and curr_col < len(board[0]):\n\t\t\t\tif check_board[curr_row][curr_col] and board[curr_row][curr_col] == word[index]:\n\t\t\t\t\tcheck_board[curr_row][curr_col] = False\n\t\t\t\t\tres = self.check_exist(check_board, board, word, index + 1, len(word), curr_row, curr_col)\n\t\t\t\t\tif res:\n\t\t\t\t\t\treturn res\n\t\t\t\t\tcheck_board[curr_row][curr_col] = True\n\t\treturn False\nif __name__ == \"__main__\":\n\ts = Solution()\n\tprint (s.exist(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\"))", + "status": 1, + "keywords": "数组,回溯,矩阵", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/78/78_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/78/78_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/78/78_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/79.json b/data_backup/leetcode/79.json new file mode 100644 index 000000000..d1f0767ea --- /dev/null +++ b/data_backup/leetcode/79.json @@ -0,0 +1,24 @@ +{ + "question_id": 80, + "question_title": "删除有序数组中的重复项 II", + "difficulty": "中等", + "question_content": "

      给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使每个元素 最多出现两次 ,返回删除后数组的新长度。

      \n

      不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。

      \n

       

      \n

      说明:

      \n

      为什么返回数值是整数,但输出的答案是数组呢?

      \n

      请注意,输入数组是以「引用」方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。

      \n

      你可以想象内部操作如下:

      \n
      \n    // nums 是以“引用”方式传递的。也就是说,不对实参做任何拷贝\n    int len = removeDuplicates(nums);// 在函数里修改输入数组对于调用者是可见的。\n    // 根据你的函数返回的长度, 它会打印出数组中 该长度范围内 的所有元素。\n    for (int i = 0; i < len; i++) {\n            print(nums[i]);\n    }
      \n

       

      \n

      示例 1:

      \n
      输入:nums = [1,1,1,2,2,3]
      输出:
      5, nums = [1,1,2,2,3]
      解释:
      函数应返回新长度 length = 5, 并且原数组的前五个元素被修改为 1, 1, 2, 2, 3 。 不需要考虑数组中超出新长度后面的元素。
      \n

      示例 2:

      \n
      输入:nums = [0,0,1,1,1,1,2,3,3]
      输出:
      7, nums = [0,0,1,1,2,3,3]
      解释:
      函数应返回新长度 length = 7, 并且原数组的前五个元素被修改为 0, 0, 1, 1, 2, 3, 3 。 不需要考虑数组中超出新长度后面的元素。
      \n

       

      \n

      提示:

      \n
        \n
      • 1 <= nums.length <= 3 * 104
      • \n
      • -104 <= nums[i] <= 104
      • \n
      • nums 已按升序排列
      • \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600470127", + "cpp": "#include \n#include \nstatic int removeDuplicates(int *nums, int numsSize)\n{\n\tif (numsSize == 0)\n\t{\n\t\treturn 0;\n\t}\n\tint i;\n\tint len = 0;\n\tint count = 1;\n\tfor (i = 1; i < numsSize; i++)\n\t{\n\t\tif (nums[len] == nums[i])\n\t\t{\n\t\t\tif (count < 2)\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t\tnums[++len] = nums[i];\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcount = 1;\n\t\t\tnums[++len] = nums[i];\n\t\t}\n\t}\n\treturn len + 1;\n}\nint main(int argc, char **argv)\n{\n\tint i, count = argc - 1;\n\tint *nums = malloc(count * sizeof(int));\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tnums[i] = atoi(argv[i + 1]);\n\t}\n\tcount = removeDuplicates(nums, count);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tprintf(\"%d \", nums[i]);\n\t}\n\tprintf(\"\\n\");\n}", + "java": "class Solution {\n\tpublic int removeDuplicates(int[] nums) {\n\t\tint i = 0;\n\t\tfor (int n : nums)\n\t\t\tif (i < 2 || n > nums[i - 2])\n\t\t\t\tnums[i++] = n;\n\t\treturn i;\n\t}\n}", + "js": "", + "python": "class Solution:\n\tdef removeDuplicates(self, nums):\n\t\t\"\"\"\n\t\t:type nums: List[int]\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tif nums is None:\n\t\t\treturn 0\n\t\tlength = len(nums)\n\t\tresult = 0\n\t\ti = j = 0\n\t\twhile i < length:\n\t\t\tj = i\n\t\t\twhile j < length:\n\t\t\t\tif nums[j] != nums[i]:\n\t\t\t\t\tbreak\n\t\t\t\tj += 1\n\t\t\tif j-i > 2:\n\t\t\t\tlength -= j-i-2\n\t\t\t\tfor k in range(j-i-2):\n\t\t\t\t\tdel nums[i]\n\t\t\t\tresult += 2\n\t\t\t\tj = i+2\n\t\t\telse:\n\t\t\t\tresult += (j-i)\n\t\t\ti = j\n\t\treturn result\n# %%\ns = Solution()\nprint(s.removeDuplicates(nums = [1,1,1,2,2,3]))", + "status": 1, + "keywords": "数组,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104349070" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/79/79_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/79/79_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/79/79_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/8.json b/data_backup/leetcode/8.json new file mode 100644 index 000000000..6a03fb908 --- /dev/null +++ b/data_backup/leetcode/8.json @@ -0,0 +1,24 @@ +{ + "question_id": 9, + "question_title": "回文数", + "difficulty": "简单", + "question_content": "

      给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false

      回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是。

       

      示例 1:

      输入:x = 121
      输出:
      true

      示例 2:

      输入:x = -121
      输出:
      false
      解释:
      从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。

      示例 3:

      输入:x = 10
      输出:
      false
      解释:
      从右向左读, 为 01 。因此它不是一个回文数。

      示例 4:

      输入:x = -101
      输出:
      false

       

      提示:

        \t
      • -231 <= x <= 231 - 1

       

      进阶:你能不将整数转为字符串来解决这个问题吗?

      ", + "topic_link": "https://bbs.csdn.net/topics/600471100", + "cpp": "bool isPalindrome(int x)\n{\n\tif (x < 0)\n\t\treturn false;\n\tchar r[11];\n\tint n = snprintf(r, 11, \"%d\", x);\n\tint i;\n\tfor (i = 0; i < n / 2; i++)\n\t{\n\t\tif (r[i] != r[n - i - 1])\n\t\t\treturn false;\n\t}\n\treturn true;\n}", + "java": "class Solution {\n\tpublic boolean isPalindrome(int x) {\n\t\tlong r;\n\t\tlong o = x;\n\t\tlong y = 0;\n\t\twhile (x > 0) {\n\t\t\tr = x % 10;\n\t\t\ty = y * 10 + r;\n\t\t\tx = (int) Math.floor(x / 10);\n\t\t}\n\t\treturn y == o;\n\t}\n}", + "js": "/**\n * @param {number} x\n * @return {boolean}\n */\nvar isPalindrome = function(x) {\n let r;\n let o=x;\n let y=0;\n while(x>0){\n r = x%10;\n y = y*10+r;\n x = Math.floor(x/10);\n }\n \n return y===o;\n};\n\nfunction main(){\n\n}\n\nmain();\n", + "python": "import math\nclass Solution:\n\tdef isPalindrome(self, x: int) -> bool:\n\t\to = x\n\t\ty = 0\n\t\twhile x > 0:\n\t\t\tr = x % 10\n\t\t\ty = y*10+r\n\t\t\tx = int(math.floor(x/10))\n\t\treturn y == o\n# %%\ns = Solution()\nprint(s.isPalindrome(x = 121))", + "status": 1, + "keywords": "数学", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/8/8_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/8/8_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/8/8_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/80.json b/data_backup/leetcode/80.json new file mode 100644 index 000000000..6056d3fd5 --- /dev/null +++ b/data_backup/leetcode/80.json @@ -0,0 +1,24 @@ +{ + "question_id": 81, + "question_title": "搜索旋转排序数组 II", + "difficulty": "中等", + "question_content": "

      已知存在一个按非降序排列的整数数组 nums ,数组中的值不必互不相同。

      \n

      在传递给函数之前,nums 在预先未知的某个下标 k0 <= k < nums.length)上进行了 旋转\n ,使数组变为 [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]](下标 从 0\n 开始 计数)。例如, [0,1,2,4,4,4,5,6,6,7] 在下标 5 处经旋转后可能变为\n [4,5,6,6,7,0,1,2,4,4] 。\n

      \n

      给你 旋转后 的数组 nums 和一个整数 target ,请你编写一个函数来判断给定的目标值是否存在于数组中。如果\n nums 中存在这个目标值 target ,则返回 true ,否则返回 false 。\n

      \n

       

      \n

      示例 1:

      \n
      输入:nums = [2,5,6,0,0,1,2], target = 0
      输出:
      true
      \n

      示例 2:

      \n
      输入:nums = [2,5,6,0,0,1,2], target = 3
      输出:
      false
      \n

       

      \n

      提示:

      \n
        \n
      • 1 <= nums.length <= 5000
      • \n
      • -104 <= nums[i] <= 104
      • \n
      • 题目数据保证 nums 在预先未知的某个下标上进行了旋转
      • \n
      • -104 <= target <= 104
      • \n
      \n

       

      \n

      进阶:

      \n
        \n
      • 这是 搜索旋转排序数组 的延伸题目,本题中的 nums \n 可能包含重复元素。
      • \n
      • 这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?
      • \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600469924", + "cpp": "#include \n#include \n#include \nstatic bool search(int *nums, int numsSize, int target)\n{\n\tint lo = 0;\n\tint hi = numsSize - 1;\n\twhile (lo <= hi)\n\t{\n\t\tint mid = lo + (hi - lo) / 2;\n\t\tif (nums[mid] == target)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\tif (nums[lo] == nums[mid] && nums[mid] == nums[hi])\n\t\t{\n\t\t\tlo++;\n\t\t\thi--;\n\t\t}\n\t\telse if (nums[lo] <= nums[mid])\n\t\t{\n\t\t\tif (nums[lo] <= target && target < nums[mid])\n\t\t\t{\n\t\t\t\thi = mid - 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = mid + 1;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (nums[mid] < target && target <= nums[hi])\n\t\t\t{\n\t\t\t\tlo = mid + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = mid - 1;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\nint main(int argc, char **argv)\n{\n\tint i;\n\tint target = atoi(argv[1]);\n\tint size = argc - 2;\n\tint *nums = malloc(size * sizeof(int));\n\tfor (i = 0; i < argc - 2; i++)\n\t{\n\t\tnums[i] = atoi(argv[i + 2]);\n\t}\n\tprintf(\"%d\\n\", search(nums, size, target));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean search(int[] nums, int target) {\n\t\tint low = 0;\n\t\tint high = nums.length - 1;\n\t\twhile (low <= high) {\n\t\t\twhile (low < high && nums[low] == nums[low + 1]) {\n\t\t\t\tlow++;\n\t\t\t}\n\t\t\twhile (low < high && nums[high] == nums[high - 1]) {\n\t\t\t\thigh--;\n\t\t\t}\n\t\t\tint mid = (low + high) / 2;\n\t\t\tif (nums[mid] == target) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (nums[mid] >= nums[0] && (target > nums[mid] || target < nums[0])) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else if (nums[mid] < nums[0] && target > nums[mid] && target < nums[0]) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef search(self, nums, target):\n\t\t\"\"\"\n\t\t:type nums: List[int]\n\t\t:type target: int\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\tdef get(start, end):\n\t\t\tif start > end:\n\t\t\t\treturn False\n\t\t\tmid = (start + end) / 2\n\t\t\tmid = int(mid)\n\t\t\twhile mid < end and nums[mid + 1] == nums[mid]:\n\t\t\t\tmid += 1\n\t\t\twhile start < mid and nums[start + 1] == nums[start]:\n\t\t\t\tstart += 1\n\t\t\tif nums[mid] == target:\n\t\t\t\treturn True\n\t\t\telif mid == end:\n\t\t\t\treturn get(start, mid - 1)\n\t\t\telif start == mid:\n\t\t\t\treturn get(mid + 1, end)\n\t\t\telif nums[mid] >= nums[start]:\n\t\t\t\tif target >= nums[start] and target < nums[mid]:\n\t\t\t\t\treturn get(start, mid - 1)\n\t\t\t\telse:\n\t\t\t\t\treturn get(mid + 1, end)\n\t\t\telif nums[mid] <= nums[end]:\n\t\t\t\tif target > nums[mid] and target <= nums[end]:\n\t\t\t\t\treturn get(mid + 1, end)\n\t\t\t\telse:\n\t\t\t\t\treturn get(start, mid - 1)\n\t\treturn get(0, len(nums) - 1)\n# %%\ns = Solution()\nprint(s.search(nums = [2,5,6,0,0,1,2], target = 0))", + "status": 1, + "keywords": "数组,二分查找", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104349456" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/80/80_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/80/80_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/80/80_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/81.json b/data_backup/leetcode/81.json new file mode 100644 index 000000000..a11d0227a --- /dev/null +++ b/data_backup/leetcode/81.json @@ -0,0 +1,24 @@ +{ + "question_id": 82, + "question_title": "删除排序链表中的重复元素 II", + "difficulty": "中等", + "question_content": "

      存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除链表中所有存在数字重复情况的节点,只保留原始链表中 没有重复出现 的数字。

      返回同样按升序排列的结果链表。

       

      示例 1:

      \"\"
      输入:head = [1,2,3,3,4,4,5]
      输出:
      [1,2,5]

      示例 2:

      \"\"
      输入:head = [1,1,1,2,3]
      输出:
      [2,3]

       

      提示:

        \t
      • 链表中节点数目在范围 [0, 300]
      • \t
      • -100 <= Node.val <= 100
      • \t
      • 题目数据保证链表已经按升序排列
      ", + "topic_link": "https://bbs.csdn.net/topics/600470128", + "cpp": "#include \n#include \nstruct ListNode\n{\n\tint val;\n\tstruct ListNode *next;\n};\nstruct ListNode *deleteDuplicates(struct ListNode *head)\n{\n\tstruct ListNode dummy;\n\tstruct ListNode *p, *q, *prev;\n\tprev = &dummy;\n\tdummy.next = head;\n\tp = q = head;\n\twhile (p != NULL)\n\t{\n\t\twhile (q != NULL && q->val == p->val)\n\t\t{\n\t\t\tq = q->next;\n\t\t}\n\t\tif (p->next == q)\n\t\t{\n\t\t\tprev = p;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprev->next = q;\n\t\t}\n\t\tp = q;\n\t}\n\treturn dummy.next;\n}\nint main(int argc, char **argv)\n{\n\tint i;\n\tstruct ListNode *head = NULL;\n\tstruct ListNode *prev = NULL;\n\tstruct ListNode *p;\n\tfor (i = 0; i < argc - 1; i++)\n\t{\n\t\tp = malloc(sizeof(*p));\n\t\tp->val = atoi(argv[i + 1]);\n\t\tp->next = NULL;\n\t\tif (head == NULL)\n\t\t{\n\t\t\thead = p;\n\t\t\tprev = head;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprev->next = p;\n\t\t\tprev = p;\n\t\t}\n\t}\n\tp = deleteDuplicates(head);\n\twhile (p != NULL)\n\t{\n\t\tprintf(\"%d \", p->val);\n\t\tp = p->next;\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode(int x) { val = x; }\n}\nclass Solution {\n\tpublic ListNode deleteDuplicates(ListNode head) {\n\t\tif (head == null || head.next == null) {\n\t\t\treturn head;\n\t\t}\n\t\tListNode next = head.next;\n\t\tif (head.val == next.val) {\n\t\t\twhile (next != null && head.val == next.val) {\n\t\t\t\tnext = next.next;\n\t\t\t}\n\t\t\thead = deleteDuplicates(next);\n\t\t} else {\n\t\t\thead.next = deleteDuplicates(next);\n\t\t}\n\t\treturn head;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef deleteDuplicates(self, head):\n\t\t\"\"\"\n\t\t:type head: ListNode\n\t\t:rtype: ListNode\n\t\t\"\"\"\n\t\tnewnodehead = None\n\t\tnewnode = None\n\t\tnode = head\n\t\twhile node:\n\t\t\tlastval = node.val\n\t\t\tif node.next and node.next.val == lastval:\n\t\t\t\twhile node and node.val == lastval:\n\t\t\t\t\tnode=node.next\n\t\t\t\tcontinue\n\t\t\tif not newnodehead:\n\t\t\t\tnewnode=ListNode(node.val)\n\t\t\t\tnewnodehead=newnode\n\t\t\telse:\n\t\t\t\tnewnode.next=ListNode(node.val)\n\t\t\t\tnewnode=newnode.next\n\t\t\tnode = node.next\n\t\treturn newnodehead\n# %%\nl = LinkList()\nlist1 = [1,2,3,3,4,4,5]\nl1 = l.initList(list1)\ns = Solution()\nprint(l.convert_list(s.deleteDuplicates(l1)))", + "status": 1, + "keywords": "链表,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104349722" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/81/81_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/81/81_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/81/81_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/82.json b/data_backup/leetcode/82.json new file mode 100644 index 000000000..ed75faf86 --- /dev/null +++ b/data_backup/leetcode/82.json @@ -0,0 +1,24 @@ +{ + "question_id": 83, + "question_title": "删除排序链表中的重复元素", + "difficulty": "简单", + "question_content": "

      存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除所有重复的元素,使每个元素 只出现一次

      返回同样按升序排列的结果链表。

       

      示例 1:

      \"\"
      输入:head = [1,1,2]
      输出:
      [1,2]

      示例 2:

      \"\"
      输入:head = [1,1,2,3,3]
      输出:
      [1,2,3]

       

      提示:

        \t
      • 链表中节点数目在范围 [0, 300]
      • \t
      • -100 <= Node.val <= 100
      • \t
      • 题目数据保证链表已经按升序排列
      ", + "topic_link": "https://bbs.csdn.net/topics/600470129", + "cpp": "#include \nusing namespace std;\nstruct ListNode\n{\n\tint val;\n\tListNode *next;\n\tListNode() : val(0), next(nullptr) {}\n\tListNode(int x) : val(x), next(nullptr) {}\n\tListNode(int x, ListNode *next) : val(x), next(next) {}\n};\nclass Solution\n{\npublic:\n\tListNode *deleteDuplicates(ListNode *head)\n\t{\n\t\tif (head == nullptr)\n\t\t{\n\t\t\treturn nullptr;\n\t\t}\n\t\tListNode *prev = head;\n\t\tListNode *p = prev->next;\n\t\twhile (p != nullptr)\n\t\t{\n\t\t\tif (p->val != prev->val)\n\t\t\t{\n\t\t\t\tprev->next = p;\n\t\t\t\tprev = p;\n\t\t\t}\n\t\t\tp = p->next;\n\t\t}\n\t\tprev->next = p;\n\t\treturn head;\n\t}\n};", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode(int x) {\n\t\tval = x;\n\t}\n}\nclass Solution {\n\tpublic ListNode deleteDuplicates(ListNode head) {\n\t\tif (head == null || head.next == null) {\n\t\t\treturn head;\n\t\t}\n\t\thead.next = deleteDuplicates(head.next);\n\t\tif (head.val == head.next.val)\n\t\t\thead = head.next;\n\t\treturn head;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef deleteDuplicates(self, head):\n\t\tif head is None:\n\t\t\treturn None\n\t\tpos = head\n\t\twhile pos is not None and pos.next is not None:\n\t\t\tif pos.val == pos.next.val:\n\t\t\t\tpos.next = pos.next.next\n\t\t\telse:\n\t\t\t\tpos = pos.next\n\t\treturn head\n# %%\nl = LinkList()\nlist1 = [1,1,2]\nl1 = l.initList(list1)\ns = Solution()\nprint(l.convert_list(s.deleteDuplicates(l1)))", + "status": 1, + "keywords": "链表", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_45176257/article/details/106487210" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/82/82_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/82/82_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/82/82_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/83.json b/data_backup/leetcode/83.json new file mode 100644 index 000000000..91953f27b --- /dev/null +++ b/data_backup/leetcode/83.json @@ -0,0 +1,24 @@ +{ + "question_id": 84, + "question_title": "柱状图中最大的矩形", + "difficulty": "困难", + "question_content": "

      给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。

      求在该柱状图中,能够勾勒出来的矩形的最大面积。

       

      以上是柱状图的示例,其中每个柱子的宽度为 1,给定的高度为 [2,1,5,6,2,3]

       

      图中阴影部分为所能勾勒出的最大矩形面积,其面积为 10 个单位。

       

      示例:

      输入: [2,1,5,6,2,3]
      输出:
      10
      ", + "topic_link": "https://bbs.csdn.net/topics/600471006", + "cpp": "#include \n#include \nstatic int largestRectangleArea(int *heights, int heightsSize)\n{\n\tint *indexes = malloc(heightsSize * sizeof(int));\n\tint *left = malloc(heightsSize * sizeof(int));\n\tint *right = malloc(heightsSize * sizeof(int));\n\tint i, pos = 0;\n\tfor (i = 0; i < heightsSize; i++)\n\t{\n\t\twhile (pos > 0 && heights[indexes[pos - 1]] >= heights[i])\n\t\t{\n\t\t\tpos--;\n\t\t}\n\t\tleft[i] = pos == 0 ? -1 : indexes[pos - 1];\n\t\tindexes[pos++] = i;\n\t}\n\tpos = 0;\n\tfor (i = heightsSize - 1; i >= 0; i--)\n\t{\n\t\twhile (pos > 0 && heights[indexes[pos - 1]] >= heights[i])\n\t\t{\n\t\t\tpos--;\n\t\t}\n\t\tright[i] = pos == 0 ? heightsSize : indexes[pos - 1];\n\t\tindexes[pos++] = i;\n\t}\n\tint max_area = 0;\n\tfor (i = 0; i < heightsSize; i++)\n\t{\n\t\tint area = heights[i] * (right[i] - left[i] - 1);\n\t\tmax_area = area > max_area ? area : max_area;\n\t}\n\treturn max_area;\n}\nint main(void)\n{\n\tint nums[] = {2, 1, 5, 6, 2, 3};\n\tint count = sizeof(nums) / sizeof(*nums);\n\tprintf(\"%d\\n\", largestRectangleArea(nums, count));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int largestRectangleArea(int[] heights) {\n\t\tint length = heights.length;\n\t\tif (length == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tint maxSize = 0;\n\t\tfor (int i = 0; i < length; i++) {\n\t\t\tint nowHeight = heights[i];\n\t\t\tint nowWidth = 0;\n\t\t\tfor (int j = i; j < length; j++) {\n\t\t\t\tif (heights[j] < nowHeight) {\n\t\t\t\t\tnowHeight = heights[j];\n\t\t\t\t}\n\t\t\t\tnowWidth++;\n\t\t\t\tif (maxSize < nowHeight * nowWidth) {\n\t\t\t\t\tmaxSize = nowHeight * nowWidth;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\treturn maxSize;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef largestRectangleArea(self, heights):\n\t\t\"\"\"\n\t\t:type heights: List[int]\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tlargest_rectangle = 0\n\t\tls = len(heights)\n\t\tstack = [-1]\n\t\ttop, pos = 0, 0\n\t\tfor pos in range(ls):\n\t\t\twhile top > 0 and heights[stack[top]] > heights[pos]:\n\t\t\t\tlargest_rectangle = max(largest_rectangle, heights[stack[top]] * (pos - stack[top - 1] - 1))\n\t\t\t\ttop -= 1\n\t\t\t\tstack.pop()\n\t\t\tstack.append(pos)\n\t\t\ttop += 1\n\t\twhile top > 0:\n\t\t\tlargest_rectangle = max(largest_rectangle, heights[stack[top]] * (ls - stack[top - 1] - 1))\n\t\t\ttop -= 1\n\t\treturn largest_rectangle\nif __name__ == \"__main__\":\n\ts = Solution()\n\tprint (s.largestRectangleArea([2,1,5,6,2,3]))", + "status": 1, + "keywords": "栈,数组,单调栈", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/83/83_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/83/83_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/83/83_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/84.json b/data_backup/leetcode/84.json new file mode 100644 index 000000000..bc5ae2181 --- /dev/null +++ b/data_backup/leetcode/84.json @@ -0,0 +1,24 @@ +{ + "question_id": 85, + "question_title": "最大矩形", + "difficulty": "困难", + "question_content": "

      给定一个仅包含 01 、大小为 rows x cols 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。

       

      示例 1:

      \"\"
      输入:matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]
      输出:
      6
      解释:
      最大矩形如上图所示。

      示例 2:

      输入:matrix = []
      输出:
      0

      示例 3:

      输入:matrix = [[\"0\"]]
      输出:
      0

      示例 4:

      输入:matrix = [[\"1\"]]
      输出:
      1

      示例 5:

      输入:matrix = [[\"0\",\"0\"]]
      输出:
      0

       

      提示:

        \t
      • rows == matrix.length
      • \t
      • cols == matrix[0].length
      • \t
      • 0 <= row, cols <= 200
      • \t
      • matrix[i][j]'0''1'
      ", + "topic_link": "https://bbs.csdn.net/topics/600470828", + "cpp": "#include \n#include \n#include \n#include \nstatic inline int max(int a, int b)\n{\n\treturn a > b ? a : b;\n}\nstatic int area_calc(int *heights, int size)\n{\n\tint *indexes = malloc(size * sizeof(int));\n\tint *lhist = malloc(size * sizeof(int));\n\tint *rhist = malloc(size * sizeof(int));\n\tint i, pos = 0;\n\tfor (i = 0; i < size; i++)\n\t{\n\t\twhile (pos > 0 && heights[indexes[pos - 1]] >= heights[i])\n\t\t{\n\t\t\tpos--;\n\t\t}\n\t\tlhist[i] = pos == 0 ? -1 : indexes[pos - 1];\n\t\tindexes[pos++] = i;\n\t}\n\tpos = 0;\n\tfor (i = size - 1; i >= 0; i--)\n\t{\n\t\twhile (pos > 0 && heights[indexes[pos - 1]] >= heights[i])\n\t\t{\n\t\t\tpos--;\n\t\t}\n\t\trhist[i] = pos == 0 ? size : indexes[pos - 1];\n\t\tindexes[pos++] = i;\n\t}\n\tint max_area = 0;\n\tfor (i = 0; i < size; i++)\n\t{\n\t\tint area = heights[i] * (rhist[i] - lhist[i] - 1);\n\t\tmax_area = max(area, max_area);\n\t}\n\treturn max_area;\n}\nstatic int maximalRectangle(char **matrix, int matrixRowSize, int matrixColSize)\n{\n\tint i, j, max_area = 0;\n\tint *heights = malloc(matrixColSize * sizeof(int));\n\tmemset(heights, 0, matrixColSize * sizeof(int));\n\tfor (i = 0; i < matrixRowSize; i++)\n\t{\n\t\tfor (j = 0; j < matrixColSize; j++)\n\t\t{\n\t\t\theights[j] = matrix[i][j] == '1' ? heights[j] + 1 : 0;\n\t\t}\n\t\tmax_area = max(max_area, area_calc(heights, matrixColSize));\n\t}\n\treturn max_area;\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test row1 row2...\\n\");\n\t\texit(-1);\n\t}\n\tint i, j;\n\tint row_size = argc - 1;\n\tint col_size = strlen(argv[1]);\n\tfor (i = 0; i < row_size; i++)\n\t{\n\t\tprintf(\"%s\\n\", argv[i + 1]);\n\t}\n\tprintf(\"%d\\n\", maximalRectangle(argv + 1, argc - 1, strlen(argv[1])));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int maximalRectangle(char[][] matrix) {\n\t\tif (matrix == null || matrix.length == 0)\n\t\t\treturn 0;\n\t\tint m = matrix.length;\n\t\tint n = matrix[0].length;\n\t\tint[] left = new int[n];\n\t\tint[] right = new int[n];\n\t\tint[] height = new int[n];\n\t\tArrays.fill(right, n);\n\t\tint cur_left = 0;\n\t\tint cur_right = n;\n\t\tint res = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tcur_left = 0;\n\t\t\tcur_right = n;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (matrix[i][j] == '1')\n\t\t\t\t\theight[j]++;\n\t\t\t\telse\n\t\t\t\t\theight[j] = 0;\n\t\t\t}\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (matrix[i][j] == '1') {\n\t\t\t\t\tleft[j] = Math.max(left[j], cur_left);\n\t\t\t\t} else {\n\t\t\t\t\tleft[j] = 0;\n\t\t\t\t\tcur_left = j + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int j = n - 1; j >= 0; j--) {\n\t\t\t\tif (matrix[i][j] == '1') {\n\t\t\t\t\tright[j] = Math.min(right[j], cur_right);\n\t\t\t\t} else {\n\t\t\t\t\tright[j] = n;\n\t\t\t\t\tcur_right = j;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\tres = Math.max(res, (right[j] - left[j]) * height[j]);\n\t\t}\n\t\treturn res;\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef maximalRectangle(self, matrix):\n\t\t\"\"\"\n\t\t:type matrix: List[List[str]]\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tif matrix is None or len(matrix) == 0:\n\t\t\treturn 0\n\t\tls_row, ls_col = len(matrix), len(matrix[0])\n\t\tleft, right, height = [0] * ls_col, [ls_col] * ls_col, [0] * ls_col\n\t\tmaxA = 0\n\t\tfor i in range(ls_row):\n\t\t\tcurr_left, curr_right = 0, ls_col\n\t\t\tfor j in range(ls_col):\n\t\t\t\tif matrix[i][j] == '1':\n\t\t\t\t\theight[j] += 1\n\t\t\t\telse:\n\t\t\t\t\theight[j] = 0\n\t\t\tfor j in range(ls_col):\n\t\t\t\tif matrix[i][j] == '1':\n\t\t\t\t\tleft[j] = max(left[j], curr_left)\n\t\t\t\telse:\n\t\t\t\t\tleft[j], curr_left = 0, j + 1\n\t\t\tfor j in range(ls_col - 1, -1, -1):\n\t\t\t\tif matrix[i][j] == '1':\n\t\t\t\t\tright[j] = min(right[j], curr_right)\n\t\t\t\telse:\n\t\t\t\t\tright[j], curr_right = ls_col, j\n\t\t\tfor j in range(ls_col):\n\t\t\t\tmaxA = max(maxA, (right[j] - left[j]) * height[j])\n\t\treturn maxA\n# %%\ns = Solution()\nmatrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\nprint(s.maximalRectangle(matrix))", + "status": 1, + "keywords": "栈,数组,动态规划,矩阵,单调栈", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/84/84_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/84/84_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/84/84_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/85.json b/data_backup/leetcode/85.json new file mode 100644 index 000000000..58a6d81ab --- /dev/null +++ b/data_backup/leetcode/85.json @@ -0,0 +1,24 @@ +{ + "question_id": 86, + "question_title": "分隔链表", + "difficulty": "中等", + "question_content": "

      给你一个链表的头节点 head 和一个特定值 x ,请你对链表进行分隔,使得所有 小于 x 的节点都出现在 大于或等于 x 的节点之前。

      你应当 保留 两个分区中每个节点的初始相对位置。

       

      示例 1:

      \"\"
      输入:head = [1,4,3,2,5,2], x = 3
      输出
      :[1,2,2,4,3,5]

      示例 2:

      输入:head = [2,1], x = 2
      输出
      :[1,2]

       

      提示:

        \t
      • 链表中节点的数目在范围 [0, 200]
      • \t
      • -100 <= Node.val <= 100
      • \t
      • -200 <= x <= 200
      ", + "topic_link": "https://bbs.csdn.net/topics/600470229", + "cpp": "#include \n#include \nstruct ListNode\n{\n\tint val;\n\tstruct ListNode *next;\n};\nstruct ListNode *partition(struct ListNode *head, int x)\n{\n\tstruct ListNode dummy;\n\tstruct ListNode *prev1 = &dummy, *pivot;\n\tdummy.next = head;\n\tfor (pivot = head; pivot != NULL; pivot = pivot->next)\n\t{\n\t\tif (pivot->val >= x)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tprev1 = pivot;\n\t}\n\tstruct ListNode *p = pivot->next;\n\tstruct ListNode *prev2 = pivot;\n\twhile (p != NULL)\n\t{\n\t\tif (p->val < x)\n\t\t{\n\t\t\tprev2->next = p->next;\n\t\t\tp->next = prev1->next;\n\t\t\tprev1->next = p;\n\t\t\tprev1 = p;\n\t\t\tp = prev2->next;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprev2 = p;\n\t\t\tp = p->next;\n\t\t}\n\t}\n\treturn dummy.next;\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test target n1 n2 n3...\\n\");\n\t\texit(-1);\n\t}\n\tint i, target = atoi(argv[1]);\n\tstruct ListNode *head = NULL;\n\tstruct ListNode *prev = NULL;\n\tstruct ListNode *p;\n\tfor (i = 0; i < argc - 2; i++)\n\t{\n\t\tp = malloc(sizeof(*p));\n\t\tp->val = atoi(argv[i + 2]);\n\t\tp->next = NULL;\n\t\tif (head == NULL)\n\t\t{\n\t\t\thead = p;\n\t\t\tprev = head;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprev->next = p;\n\t\t\tprev = p;\n\t\t}\n\t}\n\tp = partition(head, target);\n\twhile (p != NULL)\n\t{\n\t\tprintf(\"%d \", p->val);\n\t\tp = p->next;\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "java": "public class ListNode {\n\tint val;\n\tListNode next;\n\tListNode(int x) {\n\t\tval = x;\n\t}\n}\nclass Solution {\n\tpublic ListNode partition(ListNode head, int x) {\n\t\tListNode dummyHead1 = new ListNode(0);\n\t\tListNode dummyHead2 = new ListNode(0);\n\t\tListNode node1 = dummyHead1;\n\t\tListNode node2 = dummyHead2;\n\t\twhile (head != null) {\n\t\t\tif (head.val < x) {\n\t\t\t\tnode1.next = head;\n\t\t\t\thead = head.next;\n\t\t\t\tnode1 = node1.next;\n\t\t\t\tnode1.next = null;\n\t\t\t} else {\n\t\t\t\tnode2.next = head;\n\t\t\t\thead = head.next;\n\t\t\t\tnode2 = node2.next;\n\t\t\t\tnode2.next = null;\n\t\t\t}\n\t\t}\n\t\tnode1.next = dummyHead2.next;\n\t\treturn dummyHead1.next;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef partition(self, head, x):\n\t\t\"\"\"\n\t\t:type head: ListNode\n\t\t:type x: int\n\t\t:rtype: ListNode\n\t\t\"\"\"\n\t\tif head is None:\n\t\t\treturn None\n\t\tless = lesshead = None\n\t\tlast = pos = head\n\t\twhile pos is not None:\n\t\t\tif pos.val < x:\n\t\t\t\tif lesshead is None:\n\t\t\t\t\tlesshead = pos\n\t\t\t\telse:\n\t\t\t\t\tless.next = pos\n\t\t\t\tless = pos\n\t\t\t\tif head == pos:\n\t\t\t\t\tlast = head = pos.next\n\t\t\t\telse:\n\t\t\t\t\tlast.next = pos.next\n\t\t\telse:\n\t\t\t\tlast = pos\n\t\t\tpos = pos.next\n\t\tif lesshead is not None:\n\t\t\tless.next = head\n\t\telse:\n\t\t\tlesshead = head\n\t\treturn lesshead\n# %%\nl = LinkList()\nlist1 = [1,4,3,2,5,2]\nl1 = l.initList(list1)\nx = 3\ns = Solution()\nprint(l.convert_list(s.partition(l1, x)))", + "status": 1, + "keywords": "链表,双指针", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_45176257/article/details/106487204" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/85/85_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/85/85_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/85/85_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/86.json b/data_backup/leetcode/86.json new file mode 100644 index 000000000..cf8df421a --- /dev/null +++ b/data_backup/leetcode/86.json @@ -0,0 +1,24 @@ +{ + "question_id": 87, + "question_title": "扰乱字符串", + "difficulty": "困难", + "question_content": "
      使用下面描述的算法可以扰乱字符串 s 得到字符串 t :\n
        \n
      1. 如果字符串的长度为 1 ,算法停止
      2. \n
      3. 如果字符串的长度 > 1 ,执行下述步骤:\n
          \n
        • 在一个随机下标处将字符串分割成两个非空的子字符串。即,如果已知字符串 s ,则可以将其分成两个子字符串 xy\n ,且满足 s = x + y
        • \n
        • 随机 决定是要「交换两个子字符串」还是要「保持这两个子字符串的顺序不变」。即,在执行这一步骤之后,s 可能是\n s = x + y 或者 s = y + x 。\n
        • \n
        • xy 这两个子字符串上继续从步骤 1 开始递归执行此算法。
        • \n
        \n
      4. \n
      \n\n

      给你两个 长度相等 的字符串 s1\n 和 s2,判断 s2 是否是 s1 的扰乱字符串。如果是,返回\n true ;否则,返回 false 。\n

      \n\n

       

      \n\n

      示例 1:

      \n\n
      输入:s1 = \"great\", s2 = \"rgeat\"\n输出:true\n解释:s1 上可能发生的一种情形是:\n\"great\" --> \"gr/eat\" // 在一个随机下标处分割得到两个子字符串\n\"gr/eat\" --> \"gr/eat\" // 随机决定:「保持这两个子字符串的顺序不变」\n\"gr/eat\" --> \"g/r / e/at\" // 在子字符串上递归执行此算法。两个子字符串分别在随机下标处进行一轮分割\n\"g/r / e/at\" --> \"r/g / e/at\" // 随机决定:第一组「交换两个子字符串」,第二组「保持这两个子字符串的顺序不变」\n\"r/g / e/at\" --> \"r/g / e/ a/t\" // 继续递归执行此算法,将 \"at\" 分割得到 \"a/t\"\n\"r/g / e/ a/t\" --> \"r/g / e/ a/t\" // 随机决定:「保持这两个子字符串的顺序不变」\n算法终止,结果字符串和 s2 相同,都是 \"rgeat\"\n这是一种能够扰乱 s1 得到 s2 的情形,可以认为 s2 是 s1 的扰乱字符串,返回 true\n
      \n\n

      示例 2:

      \n\n
      输入:s1 = \"abcde\", s2 = \"caebd\"\n输出:false\n
      \n\n

      示例 3:

      \n\n
      输入:s1 = \"a\", s2 = \"a\"\n输出:true\n
      \n\n

       

      \n\n

      提示:

      \n\n
        \n
      • s1.length == s2.length
      • \n
      • 1 <= s1.length <= 30
      • \n
      • s1s2 由小写英文字母组成
      • \n
      \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600470832", + "cpp": "#include \n#include \n#include \n#include \nstatic bool scramble(char *s1, int low1, int high1, char *s2, int low2, int high2)\n{\n\tif (high1 - low1 != high2 - low2)\n\t{\n\t\treturn false;\n\t}\n\telse if (!memcmp(s1 + low1, s2 + low2, high1 - low1 + 1))\n\t{\n\t\treturn true;\n\t}\n\telse\n\t{\n\t\tint i, c1[128] = {0}, c2[128] = {0};\n\t\tfor (i = low1; i <= high1; i++)\n\t\t{\n\t\t\tc1[s1[i]]++;\n\t\t}\n\t\tfor (i = low2; i <= high2; i++)\n\t\t{\n\t\t\tc2[s2[i]]++;\n\t\t}\n\t\tif (memcmp(c1, c2, 128 * sizeof(int)))\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint len = high1 - low1 + 1;\n\t\t\tfor (i = 1; i < len; i++)\n\t\t\t{\n\t\t\t\tif (scramble(s1, low1, low1 + i - 1, s2, low2, low2 + i - 1) &&\n\t\t\t\t\tscramble(s1, low1 + i, high1, s2, low2 + i, high2))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif (scramble(s1, low1, low1 + i - 1, s2, high2 - i + 1, high2) &&\n\t\t\t\t\tscramble(s1, low1 + i, high1, s2, low2, high2 - i))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n}\nstatic bool isScramble(char *s1, char *s2)\n{\n\treturn scramble(s1, 0, strlen(s1) - 1, s2, 0, strlen(s2) - 1);\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test s1 s2\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", isScramble(argv[1], argv[2]) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean isScramble(String s1, String s2) {\n\t\tif (s1.length() == 0 && s2.length() == 0)\n\t\t\treturn true;\n\t\tif (s1.length() != s2.length())\n\t\t\treturn false;\n\t\treturn dfs(s1.toCharArray(), s2.toCharArray(), 0, 0, s1.length());\n\t}\n\tprivate boolean dfs(char[] s1, char[] s2, int start1, int start2, int len) {\n\t\tif (len == 1) {\n\t\t\treturn s1[start1] == s2[start2];\n\t\t}\n\t\tif (!equals(s1, s2, start1, start2, len)) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (int i = 1; i < len; i++) {\n\t\t\tif (dfs(s1, s2, start1, start2, i) && dfs(s1, s2, start1 + i, start2 + i, len - i))\n\t\t\t\treturn true;\n\t\t\tif (dfs(s1, s2, start1, start2 + len - i, i) && dfs(s1, s2, start1 + i, start2, len - i))\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic boolean equals(char[] s1, char[] s2, int start1, int start2, int len) {\n\t\tint[] charArr = new int[26];\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tcharArr[s1[start1 + i] - 'a']++;\n\t\t\tcharArr[s2[start2 + i] - 'a']--;\n\t\t}\n\t\tfor (int item : charArr) {\n\t\t\tif (item != 0)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef isScramble(self, s1, s2, memo={}):\n\t\tif len(s1) != len(s2) or sorted(s1) != sorted(s2):\n\t\t\treturn False\n\t\tif len(s1) <= len(s2) <= 1:\n\t\t\treturn s1 == s2\n\t\tif s1 == s2:\n\t\t\treturn True\n\t\tif (s1, s2) in memo:\n\t\t\treturn memo[s1, s2]\n\t\tn = len(s1)\n\t\tfor i in range(1, n):\n\t\t\ta = self.isScramble(s1[:i], s2[:i], memo) and self.isScramble(s1[i:], s2[i:], memo)\n\t\t\tif not a:\n\t\t\t\tb = self.isScramble(s1[:i], s2[-i:], memo) and self.isScramble(s1[i:], s2[:-i], memo)\n\t\t\tif a or b:\n\t\t\t\tmemo[s1, s2] = True\n\t\t\t\treturn True\n\t\tmemo[s1, s2] = False\n\t\treturn False\n# %%\ns = Solution()\nprint(s.isScramble(s1 = \"great\", s2 = \"rgeat\"))", + "status": 1, + "keywords": "字符串,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_44833195/article/details/106370719" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/86/86_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/86/86_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/86/86_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/87.json b/data_backup/leetcode/87.json new file mode 100644 index 000000000..907313bd4 --- /dev/null +++ b/data_backup/leetcode/87.json @@ -0,0 +1,24 @@ +{ + "question_id": 88, + "question_title": "合并两个有序数组", + "difficulty": "简单", + "question_content": "

      给你两个有序整数数组 nums1 nums2,请你将 nums2 合并到 nums1 使 nums1 成为一个有序数组。

      初始化 nums1nums2 的元素数量分别为 mn 。你可以假设 nums1 的空间大小等于 m + n,这样它就有足够的空间保存来自 nums2 的元素。

       

      示例 1:

      输入:nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
      输出:
      [1,2,2,3,5,6]

      示例 2:

      输入:nums1 = [1], m = 1, nums2 = [], n = 0
      输出:
      [1]

       

      提示:

        \t
      • nums1.length == m + n
      • \t
      • nums2.length == n
      • \t
      • 0 <= m, n <= 200
      • \t
      • 1 <= m + n <= 200
      • \t
      • -109 <= nums1[i], nums2[i] <= 109
      ", + "topic_link": "https://bbs.csdn.net/topics/600470926", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvoid merge(vector &nums1, int m, vector &nums2, int n)\n\t{\n\t\tint i = m - 1;\n\t\tint j = n - 1;\n\t\tint k = nums1.size() - 1;\n\t\twhile (i >= 0 && j >= 0)\n\t\t{\n\t\t\tif (nums1[i] < nums2[j])\n\t\t\t{\n\t\t\t\tnums1[k--] = nums2[j--];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tnums1[k--] = nums1[i--];\n\t\t\t}\n\t\t}\n\t\twhile (j >= 0)\n\t\t{\n\t\t\tnums1[k--] = nums2[j--];\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic void merge(int[] nums1, int m, int[] nums2, int n) {\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnums1[m] = nums2[i];\n\t\t\tm++;\n\t\t}\n\t\tint temp = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = i; j < m; j++) {\n\t\t\t\tif (nums1[i] > nums1[j]) {\n\t\t\t\t\ttemp = nums1[j];\n\t\t\t\t\tnums1[j] = nums1[i];\n\t\t\t\t\tnums1[i] = temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef merge(self, nums1, m, nums2, n):\n\t\t\"\"\"\n\t\t:type nums1: List[int]\n\t\t:type m: int\n\t\t:type nums2: List[int]\n\t\t:type n: int\n\t\t:rtype: void Do not return anything, modify nums1 in-place instead.\n\t\t\"\"\"\n\t\tp1, p2 = m - 1, n - 1\n\t\tpos = m + n - 1\n\t\twhile p1 >= 0 and p2 >= 0:\n\t\t\tif nums1[p1] >= nums2[p2]:\n\t\t\t\tnums1[pos] = nums1[p1]\n\t\t\t\tp1 -= 1\n\t\t\telse:\n\t\t\t\tnums1[pos] = nums2[p2]\n\t\t\t\tp2 -= 1\n\t\t\tpos -= 1\n\t\twhile p2 >= 0:\n\t\t\tnums1[pos] = nums2[p2]\n\t\t\tp2 -= 1\n\t\t\tpos -= 1\n\t\treturn nums1\n# %%\ns = Solution()\nprint(s.merge(nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3))", + "status": 1, + "keywords": "数组,双指针,排序", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "ttps://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/87/87_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/87/87_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/87/87_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/88.json b/data_backup/leetcode/88.json new file mode 100644 index 000000000..cefa2a7ff --- /dev/null +++ b/data_backup/leetcode/88.json @@ -0,0 +1,24 @@ +{ + "question_id": 89, + "question_title": "格雷编码", + "difficulty": "中等", + "question_content": "

      格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异。

      \n

      给定一个代表编码总位数的非负整数 n,打印其格雷编码序列。即使有多个不同答案,你也只需要返回其中一种。

      \n

      格雷编码序列必须以 0 开头。

      \n

       

      \n

      示例 1:

      \n
      输入: 2
      输出:
       [0,1,3,2]
      解释:
      00 - 001 - 111 - 310 - 2对于给定的 n,其格雷编码序列并不唯一。例如,[0,2,3,1] 也是一个有效的格雷编码序列。00 - 010 - 211 - 301 - 1
      \n

      示例 2:

      \n
      输入: 0
      输出:
       [0]
      解释:
      我们定义格雷编码序列必须以 0 开头。给定编码总位数为 n 的格雷编码序列,其长度为 2n。当 n = 0 时,长度为 20 = 1。因此,当 n = 0 时,其格雷编码序列为 [0]。
      ", + "topic_link": "https://bbs.csdn.net/topics/600470797", + "cpp": "#include \n#include \nint *grayCode(int n, int *returnSize)\n{\n\tif (n < 0)\n\t{\n\t\treturn NULL;\n\t}\n\tint i, count = 1 << n;\n\tint *codes = malloc(count * sizeof(int));\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tcodes[i] = (i >> 1) ^ i;\n\t}\n\t*returnSize = 1 << n;\n\treturn codes;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test n\\n\");\n\t\texit(-1);\n\t}\n\tint i, count;\n\tint *list = grayCode(atoi(argv[1]), &count);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tprintf(\"%d \", list[i]);\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic List grayCode(int n) {\n\t\tList res = new ArrayList<>();\n\t\tres.add(0);\n\t\tint cur;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint change = 1 << i;\n\t\t\tcur = res.size() - 1;\n\t\t\twhile (cur >= 0) {\n\t\t\t\tres.add(res.get(cur) ^ change);\n\t\t\t\tcur--;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef grayCode(self, n):\n\t\t\"\"\"\n\t\t:type n: int\n\t\t:rtype: List[int]\n\t\t\"\"\"\n\t\tres = [0]\n\t\tfor i in range(n):\n\t\t\tfor j in reversed(range(len(res))):\n\t\t\t\tres.append(res[j] + (1 << i))\n\t\treturn res\nif __name__ == \"__main__\":\n\ts = Solution()\n\tprint (s.grayCode(2))", + "status": 1, + "keywords": "位运算,数学,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/qq_25406563/article/details/85065072" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/88/88_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/88/88_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/88/88_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/89.json b/data_backup/leetcode/89.json new file mode 100644 index 000000000..38c974b1a --- /dev/null +++ b/data_backup/leetcode/89.json @@ -0,0 +1,24 @@ +{ + "question_id": 90, + "question_title": "子集 II", + "difficulty": "中等", + "question_content": "

      给你一个整数数组 nums ,其中可能包含重复元素,请你返回该数组所有可能的子集(幂集)。

      解集 不能 包含重复的子集。返回的解集中,子集可以按 任意顺序 排列。

       

      示例 1:

      输入:nums = [1,2,2]
      输出:
      [[],[1],[1,2],[1,2,2],[2],[2,2]]

      示例 2:

      输入:nums = [0]
      输出:
      [[],[0]]

       

      提示:

        \t
      • 1 <= nums.length <= 10
      • \t
      • -10 <= nums[i] <= 10
      ", + "topic_link": "https://bbs.csdn.net/topics/600469825", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tvector> subsetsWithDup(vector &nums)\n\t{\n\t\tvector> res;\n\t\tsort(nums.begin(), nums.end());\n\t\tdfs(nums, 0, res);\n\t\treturn res;\n\t}\nprivate:\n\tvector stack;\n\tvoid dfs(vector &nums, int start, vector> &res)\n\t{\n\t\tres.push_back(stack);\n\t\tint last = INT_MIN;\n\t\tfor (int i = start; i < nums.size(); i++)\n\t\t{\n\t\t\tif (last != nums[i])\n\t\t\t{\n\t\t\t\tstack.push_back(nums[i]);\n\t\t\t\tdfs(nums, i + 1, res);\n\t\t\t\tstack.pop_back();\n\t\t\t}\n\t\t\tlast = nums[i];\n\t\t}\n\t}\n};", + "java": "class Solution {\n\tpublic List> subsetsWithDup(int[] nums) {\n\t\tList> retList = new ArrayList<>();\n\t\tretList.add(new ArrayList<>());\n\t\tif (nums == null || nums.length == 0)\n\t\t\treturn retList;\n\t\tArrays.sort(nums);\n\t\tList tmp = new ArrayList<>();\n\t\ttmp.add(nums[0]);\n\t\tretList.add(tmp);\n\t\tif (nums.length == 1)\n\t\t\treturn retList;\n\t\tint lastLen = 1;\n\t\tfor (int i = 1; i < nums.length; i++) {\n\t\t\tint size = retList.size();\n\t\t\tif (nums[i] != nums[i - 1]) {\n\t\t\t\tlastLen = size;\n\t\t\t}\n\t\t\tfor (int j = size - lastLen; j < size; j++) {\n\t\t\t\tList inner = new ArrayList(retList.get(j));\n\t\t\t\tinner.add(nums[i]);\n\t\t\t\tretList.add(inner);\n\t\t\t}\n\t\t}\n\t\treturn retList;\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef subsetsWithDup(self, nums):\n\t\tnums.sort()\n\t\tres = [[]]\n\t\tbegin = 0\n\t\tfor index in range(len(nums)):\n\t\t\tif index == 0 or nums[index] != nums[index - 1]:\n\t\t\t\tbegin = 0\n\t\t\tsize = len(res)\n\t\t\tfor j in range(begin, size):\n\t\t\t\tcurr = list(res[j])\n\t\t\t\tcurr.append(nums[index])\n\t\t\t\tres.append(curr)\n\t\t\tbegin = size\n\t\treturn res\n# %%\ns = Solution()\nprint(s.subsetsWithDup(nums = [1,2,2]))", + "status": 1, + "keywords": "位运算,数组,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104361948" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/89/89_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/89/89_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/89/89_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/9.json b/data_backup/leetcode/9.json new file mode 100644 index 000000000..2c30376ab --- /dev/null +++ b/data_backup/leetcode/9.json @@ -0,0 +1,24 @@ +{ + "question_id": 10, + "question_title": "正则表达式匹配", + "difficulty": "困难", + "question_content": "

      给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配。

        \t
      • '.' 匹配任意单个字符
      • \t
      • '*' 匹配零个或多个前面的那一个元素

      所谓匹配,是要涵盖 整个 字符串 s的,而不是部分字符串。

      示例 1:

      输入:s = \"aa\" p = \"a\"
      输出:
      false
      解释:
      \"a\" 无法匹配 \"aa\" 整个字符串。

      示例 2:

      输入:s = \"aa\" p = \"a*\"
      输出:
      true
      解释:
      因为 '*' 代表可以匹配零个或多个前面的那一个元素, 在这里前面的元素就是 'a'。因此,字符串 \"aa\" 可被视为 'a' 重复了一次。

      示例 3:

      输入:s = \"ab\" p = \".*\"
      输出:
      true
      解释:
      \".*\" 表示可匹配零个或多个('*')任意字符('.')。

      示例 4:

      输入:s = \"aab\" p = \"c*a*b\"
      输出:
      true
      解释:
      因为 '*' 表示零个或多个,这里 'c' 为 0 个, 'a' 被重复一次。因此可以匹配字符串 \"aab\"。

      示例 5:

      输入:s = \"mississippi\" p = \"mis*is*p*.\"
      输出:
      false

       

      提示:

        \t
      • 0 <= s.length <= 20
      • \t
      • 0 <= p.length <= 30
      • \t
      • s 可能为空,且只包含从 a-z 的小写字母。
      • \t
      • p 可能为空,且只包含从 a-z 的小写字母,以及字符 . 和 *
      • \t
      • 保证每次出现字符 * 时,前面都匹配到有效的字符
      ", + "topic_link": "https://bbs.csdn.net/topics/600470835", + "cpp": "bool isMatch(char *s, char *p)\n{\n\tif (!p || p[0] == NULL)\n\t\treturn (!s || s[0] == NULL);\n\tbool head_match = (s && s[0] && (s[0] == p[0] || p[0] == '.'));\n\tif (p[1] && p[1] == '*')\n\t{\n\t\treturn (head_match && isMatch(s + 1, p)) || isMatch(s, p + 2);\n\t}\n\telse\n\t{\n\t\treturn head_match && isMatch(s + 1, p + 1);\n\t}\n}", + "java": "class Solution {\n\tpublic boolean isMatch(String s, String p) {\n\t\tif (p.length() == 0)\n\t\t\treturn s.length() == 0;\n\t\tboolean head_match = s.length() > 0 && (s.charAt(0) == p.charAt(0) || p.charAt(0) == '.');\n\t\tif (p.length() > 1 && p.charAt(1) == '*') {\n\t\t\treturn (head_match && isMatch(s.substring(1), p)) || isMatch(s, p.substring(2));\n\t\t} else {\n\t\t\treturn head_match && isMatch(s.substring(1), p.substring(1));\n\t\t}\n\t}\n}", + "js": "/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */\nvar isMatch = function(s, p) {\n \n let M = s.length;\n let N = p.length;\n let i = 0;\n let j = 0;\n\tlet k = 0;\n\t\n let ccid = 0;\n\n\tlet continues = [];\n\tlet preDotStarPos = {};\n let preCharStarPos = {};\n\n let c = null;\n\n const matchEmptyStar = (force)=>{\n \tlet hint = false;\n\n \t//...[\\m]\\n\n \t//...[\\w]*\n \tlet p1 = j+1=M && p[j+1]==='*';\n\n \tif(p1||p2||p3){\n \t\tj += 2;\n \t\thint = true;\n \t}\n\n \treturn hint;\n };\n\n const matchCharStar = ()=>{\n \tlet hint = false;\n \t\n \tlet p1 = i{\n \tlet hint = false;\n \tlet p1 = i{\n \tlet hint = false;\n \tlet p1 = j+10;\n \tlet p2 = j+1===N && (p[j]===c||p[j]==='.') && k>0;\n\n \tif(p1||p2){\n \t\tk -= 1;\n \t\tj += 1;\n \t\thint = true;\n \t}\n \treturn hint;\n };\n\n const matchDotContinue = (start)=>{\n \tlet hint = false;\n \tlet p1 = c==='.' && k>0 && (p[j]!=='.'&&p[j]!==s[i]) && p[j+1]!=='*';\n \tif(p1 && (i-1)>start){\n \t\ti -= 1;\n \t\tk -= 1;\n \t\thint = true;\n \t}\n \treturn hint;\n };\n\n const matchChar = ()=>{\n \tlet hint = false;\n \tlet p1 = i{\n\t\tlet hint = false;\n \tlet p1 = iM||j>=N;\n\n \tif(p1||p2||p3||p4){\n \t\thint = true;\n \t}\n \treturn hint;\n\t};\n\t\n\n\tconst preDotStar = ()=>{\n\t\tpreDotStarPos = {\n\t\t\ti,j,k,c\n\t\t};\n\t};\n\n const saveDotStar = ()=>{\n \tif(k>0){\n\t\t\tcontinues.push({\n\t\t\t\ttype: 0,\n\t\t\t\tccid,\n\t\t\t\tstart: preDotStarPos.i,\n\t\t\t\ti,j,k,c,\n\t\t\t});\n\t\t\tccid++;\n \t}\n };\n\n const preCharStar = ()=>{\n \tpreCharStarPos = {\n \t\ti,j,k,c\n \t};\n };\n\n const saveCharStar = ()=>{\n \tconst {i,j,k,c} = preCharStarPos;\n\t\tcontinues.push({\n\t\t\ttype: 1,\n\t\t\ti,j,k,c,\n\t\t\tccid\n\t\t});\n \tccid++;\n };\n\n const updateDotStar = ()=>{\n \tif(continues.length===0) {\n \t\treturn;\n \t}\n\n \tlet cc = continues[continues.length-1];\n \tif(cc.type===0){\n \t\tcc.k = k;\n\t \tcc.i = i;\n\t \tif(cc.k===0){\n\t \t\tcontinues.pop();\n\t \t}\n \t}\n }\n\n const load = ()=>{\n \tlet cc;\n \twhile(continues.length>0){\n \t\tlet ccc = continues[continues.length-1];\n \t\tif(ccc.type===0){\n \t\t\tif(ccc.k>0&&ccc.i>ccc.start){\n\t \t\t\tcc = ccc;\n\t \t\t\tbreak;\n\t \t\t}else{\n\t \t\t\tcontinues.pop();\n\t \t\t}\n \t\t}else{\n \t\t\tcc = ccc;\n \t\t\tcontinues.pop();\n \t\t\tbreak;\n \t\t}\n \t}\n\n \tif(cc==null){\n \t\treturn null;\n \t}\n \t\n \tif(cc.type===0){\n \t\ti = cc.i-1;\n\t \tj = cc.j;\n\t \tk = cc.k;\n\t \tc = cc.c;\t\n \t}else{\n \t\ti = cc.i;\n\t \tj = cc.j;\n\t \tk = cc.k;\n\t \tc = cc.c;\n \t}\n\n \treturn cc;\n\t}\n\t\n\tconst matchDotStars = ()=>{\n\t\twhile(matchEmptyStar()){}\n\t\tpreDotStar();\n\t\tif(matchDotStar()){\n\t\t\tj+=2;\n\t\t\twhile(matchEmptyStar()){}\t\n\t\t\twhile(matchDotContinue(preDotStarPos.i)) {\n\t\t\t\twhile(matchEmptyStar()){}\n\t\t\t}\n\t\t\tsaveDotStar();\n\t\t}\n\t\twhile(matchEmptyStar()){}\n\t}\n\n\tconst gotoDotStarBranch = (cc)=>{\n\t\twhile(matchDotContinue(cc.start)) {\n\t\t\twhile(matchEmptyStar()){}\n\t\t}\n\t\tupdateDotStar();\n\t}\n\n\tconst matchCharStars = ()=>{\n\t\tlet step = false;\n\t\tpreCharStar();\n\t\twhile(matchCharStar()){\n\t\t\tstep = true;\n\t\t\tsaveCharStar();\n\t\t\tpreCharStar();\n\t\t}\n\t\tif(step){\n\t\t\tj+=2;\n\t\t\twhile(true) {\n\t\t\t\twhile(matchEmptyStar()){}\n\t\t\t\tpreCharStar();\n\t\t\t\tif(!matchCharContinue()){\n\t\t\t\t\tbreak;\n\t\t\t\t}else{\n\t\t\t\t\tsaveCharStar();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twhile(matchEmptyStar()){}\n\t};\n\n\tconst gotoCharStarBranch = (cc)=>{\n\t\twhile(matchEmptyStar(true)){}\n\t}\n\n\tconst matchChars = ()=>{\n\t\twhile(matchChar()){\n\t\t\twhile(matchEmptyStar()){}\n\t\t}\n\t\twhile(matchEmptyStar()){}\n\t};\n\n const match = ()=>{\n \tlet count = 0;\n\n \twhile (true) {\n \t\t// .*\n \t\tmatchDotStars();\n\n\t\t\t// \\w*\n\t\t\tmatchCharStars();\n\n \t\t// \\w\\w\n \t\tmatchChars();\n\n \t\t// finish state\n \t\tif(matchFinishState()){\n\n\t\t\t\t// test real finish\n \t\t\tif(i===M&&j===N){\n \t\t\t\treturn true;\n \t\t\t}\n\n\t\t\t\t// else test if have continuation\n \t\t\tconst cc = load();\n \t\t\tif(cc==null){\n\t\t\t \treturn i===M && j===N;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// goto continuation and recover\n\t\t\t\tif(cc.type===0){\n\t\t\t\t\tgotoDotStarBranch(cc);\n\t\t\t\t}else{\n\t\t\t\t\tgotoCharStarBranch(cc);\n\t\t\t\t}\n \t\t}\n\t\t\twhile(matchEmptyStar()){}\n\n \t\t// count\n \t\tcount++;\n \t}\n };\n\n return match();\n}\n\nfunction main(){\n\tconst tests = [\n\t\t[\"aa\",\"a\",false],\n\t\t[\"aa\",\"a*\",true],\n\t\t[\"ab\",\".*\",true],\n\t\t[\"aab\",\"c*a*b\",true],\n\t\t[\"mississippi\",\"mis*is*ip*.\",true],\n\t\t[\"mississippi\",\"mis*is*p*.\",false],\n\t\t[\"a\",\"a*\",true],\n\t\t[\"aaaaaa\",\"a*a\",true],\n\t\t[\"aaaaaa\",\"a*aa\",true],\n\t\t[\"aaaaaa\",\"a*aaaaa\",true],\n\t\t[\"aaaaaa\",\"a*aaaaaa\",true],\n\t\t[\"aaaaaa\",\"a*aaaaaaa\",false],\n\t\t[\"a\",\"a*\",true],\n\t\t[\"a\",\"a*b\",false],\n\t\t[\"a\",\".*\",true],\n\t\t[\"aaa\",\"ab*a*c*a\", true],\n\t\t[\"aaa\",\"ab*ac*a\",true],\n\t\t[\"abcd\",\"d*\",false],\n\t\t[\"aaba\",\"ab*a*c*a\",false],\n\t\t[\"a\",\"ab*\",true],\n\t\t[\"bbbba\",\".*a*a\",true],\n\t\t[\"ab\",\".*..\",true],\n\t\t[\"\",\".*\",true],\n\t\t[\"\",\".*a*c*\",true],\n\t\t[\"\",\".*a*c*a\",false],\n\t\t[\"ab\",\".ab*a*c*\",false],\n\t\t[\"ab\",\"ab*a*c*\",true],\n\t\t[\"a\",\".*..a*\",false],\n\t\t[\"a\",\".*.aa*\",false],\n\t\t[\"a\",\".*.ba*\",false],\n\t\t[\"a\",\".*.a*\",true],\n\t\t[\"a\",\".*aa*\",true],\n\t\t[\"b\",\".*aa*\",false],\n\t\t[\"ababab\",\".*babab\",true],\n\t\t[\"ccccccccca\",\".*aa*\",true],\n\t\t[\"cccccccccaa\",\".*aa*\",true],\n\t\t[\"cccccccccaaa\",\".*aa*\",true],\n\t\t[\"cccccccccaaaa\",\".*aa*\",true],\n\t\t[\"cccccccccaaaaa\",\".*aa*\",true],\n\t\t[\"bbbbbbabbbbbbba\",\".*a\",true],\n\t\t[\"aasdfasdfasdfasdfas\",\"aasdf.*asdf.*asdf.*asdf.*s\",true],\n\t\t[\"ba\", \".*.\", true],\n\t\t[\"ba\", \".*..\", true],\n\t\t[\"ba\", \".*...\", false],\n\t\t[\"abbaaaabaabbcba\", \"a*.*ba.*c*..a*.a*.\", true],\n\t\t[\"ba\",\".a*.\",true],\n\t\t[\"bab\",\".a*.\",true],\n\t\t[\"ba\",\".a*a\",true],\n\t\t[\"baa\",\".a*a\",true],\n\t\t[\"baaa\",\".a*ac*a\",true],\n\t\t[\"bbcacbabbcbaaccabc\",\"b*a*a*.c*bb*b*.*.*\",true],\n\t\t[\"abacacccbbbcbcbb\", \".*.*.*ab*.*ab.*c*\", false],\n\t];\n\n\n\tfor(const t of tests){\n\t\tconst v = isMatch(t[0],t[1]);\n\t\tif(v===t[2]){\n\t\t\tconsole.log(`[OK] ${t[0]}, ${t[1]}, ${t[2]}===${v}`);\n\t\t}else{\n\t\t\tconsole.log(`[ERROR] ${t[0]}, ${t[1]}, ${t[2]}===${v}`);\n\t\t\tprocess.exit(0);\n\t\t}\n\t}\n}\n\nmain();\n", + "python": "class Solution:\n\tdef isMatch(self, s: str, p: str) -> bool:\n\t\tif len(p) == 0:\n\t\t\treturn len(s) == 0\n\t\thead_match = len(s) > 0 and (s[0] == p[0] or p[0] == '.')\n\t\tif len(p) > 1 and p[1] == '*':\n\t\t\tif head_match and self.isMatch(s[1:], p):\n\t\t\t\treturn True\n\t\t\treturn self.isMatch(s, p[2:])\n\t\telse:\n\t\t\tif not head_match:\n\t\t\t\treturn False\n\t\t\treturn self.isMatch(s[1:], p[1:])\n# %%\ns = Solution()\nprint(s.isMatch(s = \"aa\" , p = \"a\"))", + "status": 1, + "keywords": "递归,字符串,动态规划", + "license": { + "cpp": "csdn.net", + "python": "csdn.net", + "java": "csdn.net" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/9/9_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/9/9_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/9/9_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/90.json b/data_backup/leetcode/90.json new file mode 100644 index 000000000..fa156550d --- /dev/null +++ b/data_backup/leetcode/90.json @@ -0,0 +1,24 @@ +{ + "question_id": 91, + "question_title": "解码方法", + "difficulty": "中等", + "question_content": "

      一条包含字母 A-Z 的消息通过以下映射进行了 编码

      \n
      'A' -> 1'B' -> 2...'Z' -> 26
      \n

      解码 已编码的消息,所有数字必须基于上述映射的方法,反向映射回字母(可能有多种方法)。例如,\"11106\" 可以映射为:

      \n
        \n
      • \"AAJF\" ,将消息分组为 (1 1 10 6)
      • \n
      • \"KJF\" ,将消息分组为 (11 10 6)
      • \n
      \n

      注意,消息不能分组为  (1 11 06) ,因为 \"06\" 不能映射为 \"F\" ,这是由于 \"6\" 和\n \"06\" 在映射中并不等价。\n

      \n

      给你一个只含数字的 非空 字符串 s ,请计算并返回 解码 方法的 总数

      \n

      题目数据保证答案肯定是一个 32 位 的整数。

      \n

       

      \n

      示例 1:

      \n
      输入:s = \"12\"
      输出:
      2
      解释:
      它可以解码为 \"AB\"(1 2)或者 \"L\"(12)。
      \n

      示例 2:

      \n
      输入:s = \"226\"
      输出:
      3
      解释:
      它可以解码为 \"BZ\" (2 26), \"VF\" (22 6), 或者 \"BBF\" (2 2 6) 。
      \n

      示例 3:

      \n
      输入:s = \"0\"
      输出:
      0
      解释:
      没有字符映射到以 0 开头的数字。含有 0 的有效映射是 'J' -> \"10\" 和 'T'-> \"20\" 。由于没有字符,因此没有有效的方法对此进行解码,因为所有数字都需要映射。
      \n

      示例 4:

      \n
      输入:s = \"06\"
      输出:
      0
      解释:
      \"06\" 不能映射到 \"F\" ,因为字符串含有前导 0(\"6\" 和 \"06\" 在映射中并不等价)。
      \n

       

      \n

      提示:

      \n
        \n
      • 1 <= s.length <= 100
      • \n
      • s 只包含数字,并且可能包含前导零。
      • \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600469925", + "cpp": "#include \n#include \n#include \nstatic int numDecodings(char *s)\n{\n\tint len = strlen(s);\n\tif (len == 0)\n\t{\n\t\treturn 0;\n\t}\n\tint a = 1;\n\tint b = s[0] == '0' ? 0 : a;\n\tint c = b;\n\tfor (int i = 2; i <= len; i++)\n\t{\n\t\tc = s[i - 1] == '0' ? 0 : b;\n\t\tint num = (s[i - 2] - '0') * 10 + (s[i - 1] - '0');\n\t\tif (num >= 10 && num <= 26)\n\t\t{\n\t\t\tc += a;\n\t\t}\n\t\ta = b;\n\t\tb = c;\n\t}\n\treturn c;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test number\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%d\\n\", numDecodings(argv[1]));\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic int numDecodings(String s) {\n\t\tif (s == null || s.length() == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tint n = s.length();\n\t\tint[] dp = new int[n + 1];\n\t\tdp[0] = 1;\n\t\tdp[1] = (s.charAt(0) == '0' ? 0 : 1);\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tchar c = s.charAt(i);\n\t\t\tchar pre = s.charAt(i - 1);\n\t\t\tdp[i + 1] = c == '0' ? 0 : dp[i];\n\t\t\tif (pre == '1' || (pre == '2' && c <= '6')) {\n\t\t\t\tdp[i + 1] += dp[i - 1];\n\t\t\t}\n\t\t}\n\t\treturn dp[n];\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef numDecodings(self, s):\n\t\t\"\"\"\n\t\t:type s: str\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tls = len(s)\n\t\tif ls == 0:\n\t\t\treturn 0\n\t\tdp = [0] * ls\n\t\tfor index in range(ls):\n\t\t\tif index >= 1 and int(s[index - 1:index + 1]) < 27 and int(s[index - 1:index + 1]) >= 10:\n\t\t\t\tif index == 1:\n\t\t\t\t\tdp[index] = 1\n\t\t\t\telse:\n\t\t\t\t\tdp[index] += dp[index - 2]\n\t\t\tif int(s[index]) != 0:\n\t\t\t\tif index == 0:\n\t\t\t\t\tdp[index] = 1\n\t\t\t\telse:\n\t\t\t\t\tdp[index] += dp[index - 1]\n\t\treturn dp[ls - 1]\n# %%\ns = Solution()\nprint(s.numDecodings(s = \"12\"))", + "status": 1, + "keywords": "字符串,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104364994" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/90/90_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/90/90_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/90/90_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/91.json b/data_backup/leetcode/91.json new file mode 100644 index 000000000..8d1d131bd --- /dev/null +++ b/data_backup/leetcode/91.json @@ -0,0 +1,24 @@ +{ + "question_id": 92, + "question_title": "反转链表 II", + "difficulty": "中等", + "question_content": "给你单链表的头指针 head 和两个整数 leftright ,其中 left <= right 。请你反转从位置 left 到位置 right 的链表节点,返回 反转后的链表

       

      示例 1:

      \"\"
      输入:head = [1,2,3,4,5], left = 2, right = 4
      输出:
      [1,4,3,2,5]

      示例 2:

      输入:head = [5], left = 1, right = 1
      输出:
      [5]

       

      提示:

        \t
      • 链表中节点数目为 n
      • \t
      • 1 <= n <= 500
      • \t
      • -500 <= Node.val <= 500
      • \t
      • 1 <= left <= right <= n

       

      进阶: 你可以使用一趟扫描完成反转吗?

      ", + "topic_link": "https://bbs.csdn.net/topics/600469826", + "cpp": "#include \n#include \nstruct ListNode\n{\n\tint val;\n\tstruct ListNode *next;\n};\nstatic struct ListNode *reverseBetween(struct ListNode *head, int m, int n)\n{\n\tint i;\n\tstruct ListNode dummy;\n\tstruct ListNode *prev = &dummy;\n\tprev->next = head;\n\tfor (i = 1; i < m; i++)\n\t{\n\t\tprev = prev->next;\n\t}\n\tstruct ListNode *p = prev->next;\n\tfor (i = m; i < n; i++)\n\t{\n\t\tstruct ListNode *q = p->next;\n\t\tp->next = q->next;\n\t\tq->next = prev->next;\n\t\tprev->next = q;\n\t}\n\treturn dummy.next;\n}\nint main(int argc, char **argv)\n{\n\tif (argc < 3)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test m n 1 2 3...\\n\");\n\t\texit(-1);\n\t}\n\tint i, count = argc - 3;\n\tstruct ListNode dummy;\n\tstruct ListNode *prev = &dummy;\n\tstruct ListNode *p;\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tp = malloc(sizeof(*p));\n\t\tp->val = atoi(argv[i + 3]);\n\t\tp->next = NULL;\n\t\tprev->next = p;\n\t\tprev = p;\n\t}\n\tint m = atoi(argv[1]);\n\tint n = atoi(argv[2]);\n\tstruct ListNode *head = reverseBetween(dummy.next, m, n);\n\tfor (p = head; p != NULL; p = p->next)\n\t{\n\t\tprintf(\"%d \", p->val);\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic ListNode reverseBetween(ListNode head, int m, int n) {\n\t\tListNode dummy = new ListNode(0);\n\t\tdummy.next = head;\n\t\tListNode pre = dummy;\n\t\tfor (int i = 1; i < m; i++) {\n\t\t\tpre = pre.next;\n\t\t}\n\t\thead = pre.next;\n\t\tfor (int i = m; i < n; i++) {\n\t\t\tListNode nex = head.next;\n\t\t\thead.next = nex.next;\n\t\t\tnex.next = pre.next;\n\t\t\tpre.next = nex;\n\t\t}\n\t\treturn dummy.next;\n\t}\n}", + "js": "", + "python": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef reverseBetween(self, head, m, n):\n\t\t\"\"\"\n\t\t:type head: ListNode\n\t\t:type m: int\n\t\t:type n: int\n\t\t:rtype: ListNode\n\t\t\"\"\"\n\t\tif m == n:\n\t\t\treturn head\n\t\tsplit_node, prev, curr = None, None, head\n\t\tcount = 1\n\t\twhile count <= m and curr is not None:\n\t\t\tif count == m:\n\t\t\t\tsplit_node = prev\n\t\t\tprev = curr\n\t\t\tcurr = curr.next\n\t\t\tcount += 1\n\t\ttail, next_node = prev, None\n\t\twhile curr is not None and count <= n:\n\t\t\tnext_temp = curr.next\n\t\t\tcurr.next = prev\n\t\t\tprev = curr\n\t\t\tcurr = next_temp\n\t\t\tcount += 1\n\t\tif split_node is not None:\n\t\t\tsplit_node.next = prev\n\t\tif tail is not None:\n\t\t\ttail.next = curr\n\t\tif m == 1:\n\t\t\treturn prev\n\t\treturn head\n# %%\nl = LinkList()\nlist1 = [1,2,3,4,5]\nl1 = l.initList(list1)\nleft = 2\nright = 4\ns = Solution()\nprint(l.convert_list(s.reverseBetween(l1, left, right)))", + "status": 1, + "keywords": "链表", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_44833195/article/details/106370716" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/91/91_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/91/91_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/91/91_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/92.json b/data_backup/leetcode/92.json new file mode 100644 index 000000000..1acd7c7bd --- /dev/null +++ b/data_backup/leetcode/92.json @@ -0,0 +1,24 @@ +{ + "question_id": 93, + "question_title": "复原 IP 地址", + "difficulty": "中等", + "question_content": "

      给定一个只包含数字的字符串,用以表示一个 IP 地址,返回所有可能从 s 获得的 有效 IP 地址 。你可以按任何顺序返回答案。

      有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 '.' 分隔。

      例如:\"0.1.2.201\" 和 \"192.168.1.1\" 是 有效 IP 地址,但是 \"0.011.255.245\"、\"192.168.1.312\" 和 \"192.168@1.1\" 是 无效 IP 地址。

       

      示例 1:

      输入:s = \"25525511135\"
      输出:
      [\"255.255.11.135\",\"255.255.111.35\"]

      示例 2:

      输入:s = \"0000\"
      输出:
      [\"0.0.0.0\"]

      示例 3:

      输入:s = \"1111\"
      输出:
      [\"1.1.1.1\"]

      示例 4:

      输入:s = \"010010\"
      输出:
      [\"0.10.0.10\",\"0.100.1.0\"]

      示例 5:

      输入:s = \"101023\"
      输出:
      [\"1.0.10.23\",\"1.0.102.3\",\"10.1.0.23\",\"10.10.2.3\",\"101.0.2.3\"]

       

      提示:

        \t
      • 0 <= s.length <= 3000
      • \t
      • s 仅由数字组成
      ", + "topic_link": "https://bbs.csdn.net/topics/600470923", + "cpp": "#include \n#include \n#include \n#include \nstatic bool valid(char *ip, int len)\n{\n\tif (len > 1 && ip[0] == '0')\n\t{\n\t\treturn false;\n\t}\n\tif (len == 3)\n\t{\n\t\tint n = (ip[0] - '0') * 100 + (ip[1] - '0') * 10 + (ip[2] - '0');\n\t\tif (n > 255)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n#define WIDTH 4\nstatic void dfs(char *s, int start, char *stack, int num, char **results, int *count)\n{\n\tint i, j;\n\tif (num == 4)\n\t{\n\t\tif (s[start] == '\\0')\n\t\t{\n\t\t\tresults[*count] = malloc(3 * 4 + 3 + 1);\n\t\t\tchar *p = results[*count];\n\t\t\tfor (j = 0; j < num; j++)\n\t\t\t{\n\t\t\t\tchar *q = stack + j * WIDTH;\n\t\t\t\twhile ((*p++ = *q++) != '\\0')\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\tif (j != 3)\n\t\t\t\t{\n\t\t\t\t\t*(p - 1) = '.';\n\t\t\t\t}\n\t\t\t}\n\t\t\t(*count)++;\n\t\t}\n\t}\n\telse\n\t{\n\t\tchar *p = stack + num * WIDTH;\n\t\tchar *q = p;\n\t\tfor (i = start; s[i] != '\\0' && i < start + 3; i++)\n\t\t{\n\t\t\t*q++ = s[i];\n\t\t\t*q = '\\0';\n\t\t\tif (!valid(p, q - p))\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdfs(s, i + 1, stack, num + 1, results, count);\n\t\t\tif (num + 1 < 4)\n\t\t\t{\n\t\t\t\tmemset(stack + (num + 1) * WIDTH, 0, WIDTH);\n\t\t\t}\n\t\t}\n\t}\n}\nstatic char **restoreIpAddresses(char *s, int *returnSize)\n{\n\tint count = 0;\n\tchar **results = malloc(100 * sizeof(char *));\n\tchar addr[16] = {'\\0'};\n\tdfs(s, 0, addr, 0, results, &count);\n\t*returnSize = count;\n\treturn results;\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test num\\n\");\n\t\texit(-1);\n\t}\n\tint i, count = 0;\n\tchar **list = restoreIpAddresses(argv[1], &count);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tprintf(\"%s\\n\", list[i]);\n\t}\n}", + "java": "class Solution {\n\tprivate List res = new ArrayList<>();\n\n\tpublic List restoreIpAddresses(String s) {\n\t\tif (s.length() < 4)\n\t\t\treturn res;\n\t\tbacktrack(s, 0, new StringBuilder(), 0);\n\t\treturn res;\n\t}\n\n\tprivate void backtrack(String s, int start, StringBuilder sb, int pointNumOfSb) {\n\t\tif (pointNumOfSb > 4)\n\t\t\treturn;\n\t\tif (start == s.length() && pointNumOfSb == 4) {\n\t\t\tres.add(sb.toString().substring(1));\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = start; i < s.length() && i - start < 3; i++) {\n\t\t\tString x = s.substring(start, i + 1);\n\t\t\tif (x.charAt(0) == '0' && x.length() > 1)\n\t\t\t\treturn;\n\t\t\tif (Integer.parseInt(x) <= 255) {\n\t\t\t\tsb.append(\".\" + x);\n\t\t\t\tbacktrack(s, i + 1, sb, pointNumOfSb + 1);\n\t\t\t\tsb.delete(sb.lastIndexOf(\".\"), sb.length());\n\t\t\t}\n\t\t}\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef restoreIpAddresses(self, s):\n\t\tls = len(s)\n\t\tif ls == 0 or ls > 12:\n\t\t\treturn []\n\t\tres = []\n\t\tfor i in range(1, 4):\n\t\t\tfor j in range(1, 4):\n\t\t\t\tfor k in range(1, 4):\n\t\t\t\t\tm = ls - i - j - k\n\t\t\t\t\tif m > 0 and m <= 3:\n\t\t\t\t\t\tadd1 = s[0:i]\n\t\t\t\t\t\tadd2 = s[i:i + j]\n\t\t\t\t\t\tadd3 = s[i + j:i + j + k]\n\t\t\t\t\t\tadd4 = s[i + j + k:]\n\t\t\t\t\t\tif self.isValid(add1) and self.isValid(add2) and \\\n\t\t\t\t\t\t\t\t\t\tself.isValid(add3) and self.isValid(add4):\n\t\t\t\t\t\t\tres.append(add1 + '.' + add2 + '.' + add3 + '.' + add4)\n\t\treturn res\n\tdef isValid(self, add):\n\t\tif len(add) == 1:\n\t\t\treturn True\n\t\tif add[0] == '0':\n\t\t\treturn False\n\t\tif int(add) <= 255:\n\t\t\treturn True\n\t\treturn False\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.restoreIpAddresses('25525511135'))", + "status": 1, + "keywords": "字符串,回溯", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/92/92_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/92/92_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/92/92_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/93.json b/data_backup/leetcode/93.json new file mode 100644 index 000000000..b9a19216d --- /dev/null +++ b/data_backup/leetcode/93.json @@ -0,0 +1,24 @@ +{ + "question_id": 94, + "question_title": "二叉树的中序遍历", + "difficulty": "简单", + "question_content": "

      给定一个二叉树的根节点 root ,返回它的 中序 遍历。

       

      示例 1:

      \"\"
      输入:root = [1,null,2,3]
      输出:
      [1,3,2]

      示例 2:

      输入:root = []
      输出:
      []

      示例 3:

      输入:root = [1]
      输出:
      [1]

      示例 4:

      \"\"
      输入:root = [1,2]
      输出:
      [2,1]

      示例 5:

      \"\"
      输入:root = [1,null,2]
      输出:
      [1,2]

       

      提示:

        \t
      • 树中节点数目在范围 [0, 100]
      • \t
      • -100 <= Node.val <= 100

       

      进阶: 递归算法很简单,你可以通过迭代算法完成吗?

      ", + "topic_link": "https://bbs.csdn.net/topics/600471010", + "cpp": "#include \n#include \nstruct TreeNode\n{\n\tint val;\n\tstruct TreeNode *left;\n\tstruct TreeNode *right;\n};\nstatic void traverse(struct TreeNode *node, int *result, int *count)\n{\n\tif (node == NULL)\n\t{\n\t\treturn;\n\t}\n\ttraverse(node->left, result, count);\n\tresult[*count] = node->val;\n\t(*count)++;\n\ttraverse(node->right, result, count);\n}\nstatic int *inorderTraversal(struct TreeNode *root, int *returnSize)\n{\n\tif (root == NULL)\n\t{\n\t\t*returnSize = 0;\n\t\treturn NULL;\n\t}\n\tint count = 0;\n\tint *result = malloc(5000 * sizeof(int));\n\ttraverse(root, result, &count);\n\t*returnSize = count;\n\treturn result;\n}\nint main()\n{\n\tint count = 0;\n\tinorderTraversal(NULL, &count);\n\treturn 0;\n}", + "java": "\npublic class TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\n\tTreeNode(int x) {\n\t\tval = x;\n\t}\n}\n\nclass Solution {\n\tpublic List inorderTraversal(TreeNode root) {\n\t\tList list = new ArrayList<>();\n\t\tStack stack = new Stack<>();\n\t\tTreeNode cur = root;\n\t\twhile (cur != null || !stack.isEmpty()) {\n\t\t\tif (cur != null) {\n\t\t\t\tstack.push(cur);\n\t\t\t\tcur = cur.left;\n\t\t\t} else {\n\t\t\t\tcur = stack.pop();\n\t\t\t\tlist.add(cur.val);\n\t\t\t\tcur = cur.right;\n\t\t\t}\n\t\t}\n\t\treturn list;\n\t}\n}\n", + "js": "", + "python": "class TreeNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.left = None\n\t\tself.right = None\nclass List2Tree(object):\n\tdef __init__(self, nums: list):\n\t\tself.nums = nums\n\t\tself.queue = []\n\t\tif len(nums) == 1:\n\t\t\tself.root = TreeNode(self.nums.pop(0))\n\t\telse:\n\t\t\ta = self.nums.pop(0)\n\t\t\tb = self.nums.pop(0)\n\t\t\tc = self.nums.pop(0)\n\t\t\tself.root = TreeNode(a)\n\t\t\tif b is not None:\n\t\t\t\tself.root.left = TreeNode(b)\n\t\t\telse:\n\t\t\t\tself.root.left = b\n\t\t\tif c is not None:\n\t\t\t\tself.root.right = TreeNode(c)\n\t\t\telse:\n\t\t\t\tself.root.right = c\n\t\t\tself.queue.append(self.root.left)\n\t\t\tself.queue.append(self.root.right)\n\tdef convert(self):\n\t\twhile len(self.nums) > 0 and len(self.queue)> 0:\n\t\t\tnode = self.queue.pop(0)\n\t\t\tif node is not None:\n\t\t\t\tnum= self.nums.pop(0)\n\t\t\t\tif num is not None:\n\t\t\t\t\tnode.left = TreeNode(num)\n\t\t\t\telse:\n\t\t\t\t\tnode.left = num\n\t\t\t\tif len(self.nums) > 0:\n\t\t\t\t\tnum = self.nums.pop(0)\n\t\t\t\telse:\n\t\t\t\t\tnum = None\n\t\t\t\tif num is not None:\n\t\t\t\t\tnode.right = TreeNode(num)\n\t\t\t\telse:\n\t\t\t\t\tnode.right = num\n\t\t\t\tself.queue.append(node.left)\n\t\t\t\tself.queue.append(node.right)\n\t\treturn self.root\nclass Solution(object):\n\tdef inorderTraversal(self, root):\n\t\tif root is None:\n\t\t\treturn []\n\t\troot = List2Tree(root).convert()\n\t\tres = []\n\t\tstack = [root]\n\t\twhile len(stack) > 0:\n\t\t\tcurr = stack.pop()\n\t\t\tif not isinstance(curr, TreeNode):\n\t\t\t\tres.append(curr)\n\t\t\t\tcontinue\n\t\t\tif curr.right is not None:\n\t\t\t\tstack.append(curr.right)\n\t\t\tstack.append(curr.val)\n\t\t\tif curr.left is not None:\n\t\t\t\tstack.append(curr.left)\n\t\treturn res\n# %%\ns = Solution()\nprint(s.inorderTraversal(root = [1,None,2,3]))", + "status": 1, + "keywords": "栈,树,深度优先搜索,二叉树", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/93/93_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/93/93_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/93/93_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/94.json b/data_backup/leetcode/94.json new file mode 100644 index 000000000..98c49c651 --- /dev/null +++ b/data_backup/leetcode/94.json @@ -0,0 +1,24 @@ +{ + "question_id": 95, + "question_title": "不同的二叉搜索树 II", + "difficulty": "中等", + "question_content": "
      \n

      给你一个整数 n ,请你生成并返回所有由 n 个节点组成且节点值从 1n 互不相同的不同\n 二叉搜索树 。可以按 任意顺序 返回答案。\n

      \n\n

       

      \n\n
      \n
      \n

      示例 1:

      \n \"\"\n
      输入:n = 3\n输出:[[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]\n    
      \n\n

      示例 2:

      \n\n
      输入:n = 1\n输出:[[1]]\n    
      \n\n

       

      \n\n

      提示:

      \n\n
        \n
      • 1 <= n <= 8
      • \n
      \n
      \n
      \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600471004", + "cpp": "#include \n#include \nstruct TreeNode\n{\n\tint val;\n\tstruct TreeNode *left;\n\tstruct TreeNode *right;\n};\nstatic struct TreeNode *dfs(int low, int high, int *count)\n{\n\tint i, j, k;\n\tif (low > high)\n\t{\n\t\t*count = 0;\n\t\treturn NULL;\n\t}\n\telse if (low == high)\n\t{\n\t\tstruct TreeNode *node = malloc(sizeof(*node));\n\t\tnode->val = low;\n\t\tnode->left = NULL;\n\t\tnode->right = NULL;\n\t\t*count = 1;\n\t\treturn node;\n\t}\n\telse\n\t{\n\t\t*count = 0;\n\t\tint capacity = 5;\n\t\tstruct TreeNode *roots = malloc(capacity * sizeof(struct TreeNode));\n\t\tfor (i = low; i <= high; i++)\n\t\t{\n\t\t\tint left_cnt, right_cnt;\n\t\t\tstruct TreeNode *left_subs = dfs(low, i - 1, &left_cnt);\n\t\t\tstruct TreeNode *right_subs = dfs(i + 1, high, &right_cnt);\n\t\t\tif (left_cnt == 0)\n\t\t\t\tleft_cnt = 1;\n\t\t\tif (right_cnt == 0)\n\t\t\t\tright_cnt = 1;\n\t\t\tif (*count + (left_cnt * right_cnt) >= capacity)\n\t\t\t{\n\t\t\t\tcapacity *= 2;\n\t\t\t\tcapacity += left_cnt * right_cnt;\n\t\t\t\troots = realloc(roots, capacity * sizeof(struct TreeNode));\n\t\t\t}\n\t\t\tfor (j = 0; j < left_cnt; j++)\n\t\t\t{\n\t\t\t\tfor (k = 0; k < right_cnt; k++)\n\t\t\t\t{\n\t\t\t\t\troots[*count].val = i;\n\t\t\t\t\troots[*count].left = left_subs == NULL ? NULL : &left_subs[j];\n\t\t\t\t\troots[*count].right = right_subs == NULL ? NULL : &right_subs[k];\n\t\t\t\t\t(*count)++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn roots;\n\t}\n}\nstatic struct TreeNode **generateTrees(int n, int *returnSize)\n{\n\tint i, count = 0;\n\tstruct TreeNode *roots = dfs(1, n, &count);\n\tstruct TreeNode **results = malloc(count * sizeof(struct TreeNode *));\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tresults[i] = &roots[i];\n\t}\n\t*returnSize = count;\n\treturn results;\n}\nstatic void dump(struct TreeNode *node)\n{\n\tprintf(\"%d \", node->val);\n\tif (node->left != NULL)\n\t{\n\t\tdump(node->left);\n\t}\n\telse\n\t{\n\t\tprintf(\"# \");\n\t}\n\tif (node->right != NULL)\n\t{\n\t\tdump(node->right);\n\t}\n\telse\n\t{\n\t\tprintf(\"# \");\n\t}\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 2)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test n\\n\");\n\t\texit(-1);\n\t}\n\tint i, count = 0;\n\tstruct TreeNode **results = generateTrees(atoi(argv[1]), &count);\n\tfor (i = 0; i < count; i++)\n\t{\n\t\tdump(results[i]);\n\t\tprintf(\"\\n\");\n\t}\n\treturn 0;\n}", + "java": "class TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\n\tTreeNode(int x) {\n\t\tval = x;\n\t}\n}\n\nclass Solution {\n\tpublic List generateTrees(int n) {\n\n\t\tif (n == 0)\n\t\t\treturn new LinkedList();\n\n\t\treturn generate_trees(1, n);\n\t}\n\n\tprivate LinkedList generate_trees(int start, int end) {\n\t\tLinkedList all_trees = new LinkedList();\n\n\t\tif (start > end) {\n\t\t\tall_trees.add(null);\n\t\t\treturn all_trees;\n\t\t}\n\n\t\tfor (int i = start; i <= end; i++) {\n\t\t\tLinkedList left_trees = generate_trees(start, i - 1);\n\t\t\tLinkedList right_trees = generate_trees(i + 1, end);\n\n\t\t\tfor (TreeNode l : left_trees)\n\t\t\t\tfor (TreeNode r : right_trees) {\n\t\t\t\t\tTreeNode current_tree = new TreeNode(i);\n\t\t\t\t\tcurrent_tree.left = l;\n\t\t\t\t\tcurrent_tree.right = r;\n\t\t\t\t\tall_trees.add(current_tree);\n\t\t\t\t}\n\t\t}\n\n\t\treturn all_trees;\n\t}\n}", + "js": "", + "python": "class TreeNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.left = None\n\t\tself.right = None\n\tdef to_list(self, count):\n\t\tqueue = []\n\t\tqueue.append(self)\n\t\tresult = []\n\t\twhile len(queue) > 0:\n\t\t\tif count == 0:\n\t\t\t\tbreak\n\t\t\tnode = queue.pop(0)\n\t\t\tif node is None:\n\t\t\t\tresult.append('null')\n\t\t\telse:\n\t\t\t\tcount -= 1\n\t\t\t\tresult.append(node.val)\n\t\t\t\tqueue.append(node.left)\n\t\t\t\tqueue.append(node.right)\n\t\treturn result\nclass Solution(object):\n\tdef generateTrees(self, n):\n\t\t\"\"\"\n\t\t:type n: int\n\t\t:rtype: List[TreeNode]\n\t\t\"\"\"\n\t\tif n == 0:\n\t\t\treturn []\n\t\treturn self.get_trees(1, n)\n\tdef get_trees_impl(self, start, end):\n\t\ttrees = []\n\t\tif start > end:\n\t\t\ttrees.append(None)\n\t\t\treturn trees\n\t\tfor i in range(start, end + 1):\n\t\t\tlefts = self.get_trees_impl(start, i - 1)\n\t\t\trights = self.get_trees_impl(i + 1, end)\n\t\t\tfor j in range(len(lefts)):\n\t\t\t\tfor k in range(len(rights)):\n\t\t\t\t\troot = TreeNode(i)\n\t\t\t\t\troot.left = lefts[j]\n\t\t\t\t\troot.right = rights[k]\n\t\t\t\t\ttrees.append(root)\n\t\treturn trees\n\tdef get_trees(self, start, end):\n\t\ttrees = self.get_trees_impl(start, end)\n\t\tresults = []\n\t\tfor tree in trees:\n\t\t\tif tree is None:\n\t\t\t\tresults.append([])\n\t\t\telse:\n\t\t\t\tresults.append(tree.to_list(end))\n\t\treturn results\n# %%\ns = Solution()\nprint(s.generateTrees(n=3))", + "status": 1, + "keywords": "树,二叉搜索树,动态规划,回溯,二叉树", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/94/94_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/94/94_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/94/94_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/95.json b/data_backup/leetcode/95.json new file mode 100644 index 000000000..cd2581206 --- /dev/null +++ b/data_backup/leetcode/95.json @@ -0,0 +1,24 @@ +{ + "question_id": 96, + "question_title": "不同的二叉搜索树", + "difficulty": "中等", + "question_content": "
      \n

      给你一个整数 n ,求恰由 n 个节点组成且节点值从 1n 互不相同的 二叉搜索树\n 有多少种?返回满足题意的二叉搜索树的种数。

      \n\n

       

      \n\n

      示例 1:

      \n \"\"\n
      输入:n = 3\n输出:5\n    
      \n\n

      示例 2:

      \n\n
      输入:n = 1\n输出:1\n    
      \n\n

       

      \n\n

      提示:

      \n\n
        \n
      • 1 <= n <= 19
      • \n
      \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600469926", + "cpp": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint numTrees(int n)\n\t{\n\t\tvector sum(n + 1);\n\t\tsum[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < i; j++)\n\t\t\t{\n\t\t\t\tsum[i] += sum[j] * sum[i - j - 1];\n\t\t\t}\n\t\t}\n\t\treturn sum[n];\n\t}\n}", + "java": "class Solution {\n\tpublic int numTrees(int n) {\n\t\tif (n < 2) {\n\t\t\treturn 1;\n\t\t}\n\n\t\tint[] count = new int[n + 1];\n\t\tcount[0] = 1;\n\t\tcount[1] = 1;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tint sum = 0;\n\t\t\tfor (int root = 1; root <= i; root++) {\n\t\t\t\tsum = sum + count[root - 1] * count[i - root];\n\t\t\t}\n\t\t\tcount[i] = sum;\n\t\t}\n\n\t\treturn count[n];\n\t}\n}\n", + "js": "", + "python": "class Solution(object):\n\tdef numTrees(self, n):\n\t\t\"\"\"\n\t\t:type n: int\n\t\t:rtype: int\n\t\t\"\"\"\n\t\tdp = [0] * (n + 1)\n\t\tdp[0] = 1\n\t\tdp[1] = 1\n\t\tfor level in range(2, n + 1):\n\t\t\tfor root in range(1, level + 1):\n\t\t\t\tdp[level] += dp[level - root] * dp[root - 1]\n\t\treturn dp[n]\n# %%\ns = Solution()\nprint(s.numTrees(n = 3))", + "status": 1, + "keywords": "树,二叉搜索树,数学,动态规划,二叉树", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/95/95_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/95/95_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/95/95_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/96.json b/data_backup/leetcode/96.json new file mode 100644 index 000000000..bbaae6c72 --- /dev/null +++ b/data_backup/leetcode/96.json @@ -0,0 +1,24 @@ +{ + "question_id": 97, + "question_title": "交错字符串", + "difficulty": "中等", + "question_content": "

      给定三个字符串 s1s2s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。

      两个字符串 st 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空 子字符串:

        \t
      • s = s1 + s2 + ... + sn
      • \t
      • t = t1 + t2 + ... + tm
      • \t
      • |n - m| <= 1
      • \t
      • 交错s1 + t1 + s2 + t2 + s3 + t3 + ... 或者 t1 + s1 + t2 + s2 + t3 + s3 + ...

      提示:a + b 意味着字符串 ab 连接。

       

      示例 1:

      \"\"
      输入:s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbcbcac\"
      输出:
      true

      示例 2:

      输入:s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbbaccc\"
      输出:
      false

      示例 3:

      输入:s1 = \"\", s2 = \"\", s3 = \"\"
      输出:
      true

       

      提示:

        \t
      • 0 <= s1.length, s2.length <= 100
      • \t
      • 0 <= s3.length <= 200
      • \t
      • s1s2、和 s3 都由小写英文字母组成
      ", + "topic_link": "https://bbs.csdn.net/topics/600471101", + "cpp": "#include \n#include \n#include \n#include \nstatic bool isInterleave(char *s1, char *s2, char *s3)\n{\n\tint i, j;\n\tint len1 = strlen(s1);\n\tint len2 = strlen(s2);\n\tint len3 = strlen(s3);\n\tif (len1 + len2 != len3)\n\t{\n\t\treturn false;\n\t}\n\tbool *table = malloc((len1 + 1) * (len2 + 1) * sizeof(bool));\n\tbool **dp = malloc((len1 + 1) * sizeof(bool *));\n\tfor (i = 0; i < len1 + 1; i++)\n\t{\n\t\tdp[i] = &table[i * (len2 + 1)];\n\t}\n\tdp[0][0] = true;\n\tfor (i = 1; i < len1 + 1; i++)\n\t{\n\t\tdp[i][0] = dp[i - 1][0] && s1[i - 1] == s3[i - 1];\n\t}\n\tfor (i = 1; i < len2 + 1; i++)\n\t{\n\t\tdp[0][i] = dp[0][i - 1] && s2[i - 1] == s3[i - 1];\n\t}\n\tfor (i = 1; i < len1 + 1; i++)\n\t{\n\t\tfor (j = 1; j < len2 + 1; j++)\n\t\t{\n\t\t\tbool up = dp[i - 1][j] && s1[i - 1] == s3[i + j - 1];\n\t\t\tbool left = dp[i][j - 1] && s2[j - 1] == s3[i + j - 1];\n\t\t\tdp[i][j] = up || left;\n\t\t}\n\t}\n\treturn dp[len1][len2];\n}\nint main(int argc, char **argv)\n{\n\tif (argc != 4)\n\t{\n\t\tfprintf(stderr, \"Usage: ./test s1 s2 s3\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"%s\\n\", isInterleave(argv[1], argv[2], argv[3]) ? \"true\" : \"false\");\n\treturn 0;\n}", + "java": "class Solution {\n\tpublic boolean isInterleave(String s1, String s2, String s3) {\n\t\tif ((s1.length() + s2.length()) != s3.length())\n\t\t\treturn false;\n\t\tboolean[][] dp = new boolean[s2.length() + 1][s1.length() + 1];\n\t\tdp[0][0] = true;\n\t\tfor (int i = 1; i <= s1.length(); i++) {\n\t\t\tdp[0][i] = dp[0][i - 1] && s1.charAt(i - 1) == s3.charAt(i - 1) ? true : false;\n\t\t}\n\t\tfor (int i = 1; i <= s2.length(); i++) {\n\t\t\tdp[i][0] = dp[i - 1][0] && s2.charAt(i - 1) == s3.charAt(i - 1) ? true : false;\n\t\t}\n\t\tfor (int i = 1; i < dp.length; i++) {\n\t\t\tfor (int j = 1; j < dp[0].length; j++) {\n\t\t\t\tdp[i][j] = (dp[i][j - 1] && s1.charAt(j - 1) == s3.charAt(i + j - 1))\n\t\t\t\t\t\t|| (dp[i - 1][j] && s2.charAt(i - 1) == s3.charAt(i + j - 1));\n\t\t\t}\n\t\t}\n\t\treturn dp[s2.length()][s1.length()];\n\t}\n}", + "js": "", + "python": "class Solution(object):\n\tdef isInterleave(self, s1, s2, s3):\n\t\t\"\"\"\n\t\t:type s1: str\n\t\t:type s2: str\n\t\t:type s3: str\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\tif len(s1) + len(s2) != len(s3):\n\t\t\treturn False\n\t\tqueue = [(0, 0), (-1, -1)]\n\t\tvisited = set()\n\t\tisSuccess = False\n\t\tindex = 0\n\t\twhile len(queue) != 1 or queue[0][0] != -1:\n\t\t\tp = queue.pop(0)\n\t\t\tif p[0] == len(s1) and p[1] == len(s2):\n\t\t\t\treturn True\n\t\t\tif p[0] == -1:\n\t\t\t\tqueue.append(p)\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\tif p in visited:\n\t\t\t\tcontinue\n\t\t\tvisited.add(p)\n\t\t\tif p[0] < len(s1):\n\t\t\t\tif s1[p[0]] == s3[index]:\n\t\t\t\t\tqueue.append((p[0] + 1, p[1]))\n\t\t\tif p[1] < len(s2):\n\t\t\t\tif s2[p[1]] == s3[index]:\n\t\t\t\t\tqueue.append((p[0], p[1] + 1))\n\t\treturn False\n# %%\ns = Solution()\nprint(s.isInterleave(s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbcbcac\"))", + "status": 1, + "keywords": "字符串,动态规划", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104374282" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/96/96_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/96/96_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/96/96_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/97.json b/data_backup/leetcode/97.json new file mode 100644 index 000000000..f246574fd --- /dev/null +++ b/data_backup/leetcode/97.json @@ -0,0 +1,24 @@ +{ + "question_id": 98, + "question_title": "验证二叉搜索树", + "difficulty": "中等", + "question_content": "
      \n

      给你一个二叉树的根节点 root ,判断其是否是一个有效的二叉搜索树。

      \n\n

      有效 二叉搜索树定义如下:

      \n\n
        \n
      • 节点的左子树只包含 小于 当前节点的数。
      • \n
      • 节点的右子树只包含 大于 当前节点的数。
      • \n
      • 所有左子树和右子树自身必须也是二叉搜索树。
      • \n
      \n\n

       

      \n\n

      示例 1:

      \n \"\"\n
      输入:root = [2,1,3]\n输出:true\n
      \n\n

      示例 2:

      \n \"\"\n
      输入:root = [5,1,4,null,null,3,6]\n输出:false\n解释:根节点的值是 5 ,但是右子节点的值是 4 。\n
      \n\n

       

      \n\n

      提示:

      \n\n
        \n
      • 树中节点数目范围在[1, 104]
      • \n
      • -231 <= Node.val <= 231 - 1
      • \n
      \n
      ", + "topic_link": "https://bbs.csdn.net/topics/600469827", + "cpp": "#include \nusing namespace std;\nstruct TreeNode\n{\n\tint val;\n\tTreeNode *left;\n\tTreeNode *right;\n\tTreeNode() : val(0), left(nullptr), right(nullptr) {}\n\tTreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n\tTreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n};\nclass Solution\n{\npublic:\n\tbool isValidBST(TreeNode *root)\n\t{\n\t\tstack stk;\n\t\tint prev = INT_MIN;\n\t\tbool first = true;\n\t\twhile (!stk.empty() || root != nullptr)\n\t\t{\n\t\t\tif (root != nullptr)\n\t\t\t{\n\t\t\t\tstk.push(root);\n\t\t\t\troot = root->left;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\troot = stk.top();\n\t\t\t\tstk.pop();\n\t\t\t\tif (!first && prev >= root->val)\n\t\t\t\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tfirst = false;\n\t\t\t\tprev = root->val;\n\t\t\t\troot = root->right;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n};", + "java": "\npublic class TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\n\tTreeNode(int x) {\n\t\tval = x;\n\t}\n}\n\nclass Solution {\n\tpublic boolean isValidBST(TreeNode root) {\n\n\t\tif (root == null)\n\t\t\treturn true;\n\t\tif (root.left == null && root.right == null) {\n\t\t\treturn true;\n\t\t}\n\t\tif (root.left != null) {\n\t\t\tTreeNode cur = root.left;\n\t\t\twhile (cur.right != null) {\n\t\t\t\tcur = cur.right;\n\t\t\t}\n\t\t\tif (cur.val >= root.val) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\tif (root.right != null) {\n\t\t\tTreeNode cur = root.right;\n\t\t\twhile (cur.left != null) {\n\t\t\t\tcur = cur.left;\n\t\t\t}\n\t\t\tif (cur.val <= root.val) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tboolean left = isValidBST(root.left);\n\t\tboolean right = isValidBST(root.right);\n\n\t\treturn left && right;\n\t}\n}", + "js": "", + "python": "import sys\nclass TreeNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.left = None\n\t\tself.right = None\nclass List2Tree(object):\n\tdef __init__(self, nums: list):\n\t\tself.nums = nums\n\t\tself.queue = []\n\t\tif len(nums) == 1:\n\t\t\tself.root = TreeNode(self.nums.pop(0))\n\t\telse:\n\t\t\ta = self.nums.pop(0)\n\t\t\tb = self.nums.pop(0)\n\t\t\tc = self.nums.pop(0)\n\t\t\tself.root = TreeNode(a)\n\t\t\tif b is not None:\n\t\t\t\tself.root.left = TreeNode(b)\n\t\t\telse:\n\t\t\t\tself.root.left = b\n\t\t\tif c is not None:\n\t\t\t\tself.root.right = TreeNode(c)\n\t\t\telse:\n\t\t\t\tself.root.right = c\n\t\t\tself.queue.append(self.root.left)\n\t\t\tself.queue.append(self.root.right)\n\tdef convert(self):\n\t\twhile len(self.nums) > 0 and len(self.queue)> 0:\n\t\t\tnode = self.queue.pop(0)\n\t\t\tif node is not None:\n\t\t\t\tnum= self.nums.pop(0)\n\t\t\t\tif num is not None:\n\t\t\t\t\tnode.left = TreeNode(num)\n\t\t\t\telse:\n\t\t\t\t\tnode.left = num\n\t\t\t\tif len(self.nums) > 0:\n\t\t\t\t\tnum = self.nums.pop(0)\n\t\t\t\telse:\n\t\t\t\t\tnum = None\n\t\t\t\tif num is not None:\n\t\t\t\t\tnode.right = TreeNode(num)\n\t\t\t\telse:\n\t\t\t\t\tnode.right = num\n\t\t\t\tself.queue.append(node.left)\n\t\t\t\tself.queue.append(node.right)\n\t\treturn self.root\nclass Solution(object):\n\tdef isValidBST(self, root):\n\t\troot = List2Tree(root).convert()\n\t\treturn self.isVaild_helper(root, -sys.maxsize - 1, sys.maxsize)\n\tdef isVaild_helper(self, root, minVal, maxVal):\n\t\tif root is None:\n\t\t\treturn True\n\t\tif root.val >= maxVal or root.val <= minVal:\n\t\t\treturn False\n\t\treturn self.isVaild_helper(root.left, minVal, root.val) and self.isVaild_helper(root.right, root.val, maxVal)\n# %%\ns = Solution()\nprint(s.isValidBST([5,1,4,None,None,3,6]))", + "status": 1, + "keywords": "树,深度优先搜索,二叉搜索树,二叉树", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://github.com/zhangyu345293721/leetcode" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/97/97_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/97/97_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/97/97_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/98.json b/data_backup/leetcode/98.json new file mode 100644 index 000000000..e7175185b --- /dev/null +++ b/data_backup/leetcode/98.json @@ -0,0 +1,24 @@ +{ + "question_id": 99, + "question_title": "恢复二叉搜索树", + "difficulty": "中等", + "question_content": "

      给你二叉搜索树的根节点 root ,该树中的两个节点被错误地交换。请在不改变其结构的情况下,恢复这棵树。

      进阶:使用 O(n) 空间复杂度的解法很容易实现。你能想出一个只使用常数空间的解决方案吗?

       

      示例 1:

      \"\"
      输入:root = [1,3,null,null,2]
      输出:
      [3,1,null,null,2]
      解释:
      3 不能是 1 左孩子,因为 3 > 1 。交换 1 和 3 使二叉搜索树有效。

      示例 2:

      \"\"
      输入:root = [3,1,4,null,null,2]
      输出:
      [2,1,4,null,null,3]
      解释:
      2 不能在 3 的右子树中,因为 2 < 3 。交换 2 和 3 使二叉搜索树有效。

       

      提示:

        \t
      • 树上节点的数目在范围 [2, 1000]
      • \t
      • -231 <= Node.val <= 231 - 1
      ", + "topic_link": "https://bbs.csdn.net/topics/600470826", + "cpp": "#include \nusing namespace std;\nstruct TreeNode\n{\n\tint val;\n\tTreeNode *left;\n\tTreeNode *right;\n\tTreeNode() : val(0), left(nullptr), right(nullptr) {}\n\tTreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n\tTreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n};\nclass Solution\n{\npublic:\n\tvoid recoverTree(TreeNode *root)\n\t{\n\t\tdfs(root);\n\t\tint tmp = p0_->val;\n\t\tp0_->val = p1_->val;\n\t\tp1_->val = tmp;\n\t}\nprivate:\n\tint wrong_ = 0;\n\tTreeNode *prev_ = nullptr;\n\tTreeNode *p0_ = nullptr;\n\tTreeNode *p1_ = nullptr;\n\tvoid dfs(TreeNode *root)\n\t{\n\t\tif (root == nullptr || wrong_ == 2)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tdfs(root->left);\n\t\tif (prev_ != nullptr && prev_->val > root->val)\n\t\t{\n\t\t\tif (++wrong_ == 1)\n\t\t\t{\n\t\t\t\tp0_ = prev_;\n\t\t\t\tp1_ = root;\n\t\t\t}\n\t\t\telse if (wrong_ == 2)\n\t\t\t{\n\t\t\t\tp1_ = root;\n\t\t\t}\n\t\t}\n\t\tprev_ = root;\n\t\tdfs(root->right);\n\t}\n};", + "java": "public class TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\n\tTreeNode() {\n\t}\n\n\tTreeNode(int val) {\n\t\tthis.val = val;\n\t}\n\n\tTreeNode(int val, TreeNode left, TreeNode right) {\n\t\tthis.val = val;\n\t\tthis.left = left;\n\t\tthis.right = right;\n\t}\n}\n\nclass Solution {\n\tTreeNode t1, t2, pre;\n\n\tpublic void recoverTree(TreeNode root) {\n\t\tinorder(root);\n\t\tint temp = t1.val;\n\t\tt1.val = t2.val;\n\t\tt2.val = temp;\n\t}\n\n\tpublic void inorder(TreeNode root) {\n\t\tif (root == null)\n\t\t\treturn;\n\t\tinorder(root.left);\n\t\tif (pre != null && pre.val > root.val) {\n\t\t\tif (t1 == null)\n\t\t\t\tt1 = pre;\n\t\t\tt2 = root;\n\t\t}\n\t\tpre = root;\n\t\tinorder(root.right);\n\t}\n}", + "js": "", + "python": "import sys\nclass TreeNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.left = None\n\t\tself.right = None\n\tdef to_list(self, count):\n\t\tqueue = []\n\t\tqueue.append(self)\n\t\tresult = []\n\t\twhile len(queue) > 0:\n\t\t\tif count == 0:\n\t\t\t\tbreak\n\t\t\tnode = queue.pop(0)\n\t\t\tif node is None:\n\t\t\t\tresult.append('null')\n\t\t\telse:\n\t\t\t\tcount -= 1\n\t\t\t\tresult.append(node.val)\n\t\t\t\tqueue.append(node.left)\n\t\t\t\tqueue.append(node.right)\n\t\treturn result\nclass List2Tree(object):\n\tdef __init__(self, nums: list):\n\t\tself.nums = nums\n\t\tself.queue = []\n\t\tif len(nums) == 1:\n\t\t\tself.root = TreeNode(self.nums.pop(0))\n\t\telse:\n\t\t\ta = self.nums.pop(0)\n\t\t\tb = self.nums.pop(0)\n\t\t\tc = self.nums.pop(0)\n\t\t\tself.root = TreeNode(a)\n\t\t\tif b is not None:\n\t\t\t\tself.root.left = TreeNode(b)\n\t\t\telse:\n\t\t\t\tself.root.left = b\n\t\t\tif c is not None:\n\t\t\t\tself.root.right = TreeNode(c)\n\t\t\telse:\n\t\t\t\tself.root.right = c\n\t\t\tself.queue.append(self.root.left)\n\t\t\tself.queue.append(self.root.right)\n\tdef convert(self):\n\t\twhile len(self.nums) > 0 and len(self.queue) > 0:\n\t\t\tnode = self.queue.pop(0)\n\t\t\tif node is not None:\n\t\t\t\tnum = self.nums.pop(0)\n\t\t\t\tif num is not None:\n\t\t\t\t\tnode.left = TreeNode(num)\n\t\t\t\telse:\n\t\t\t\t\tnode.left = num\n\t\t\t\tif len(self.nums) > 0:\n\t\t\t\t\tnum = self.nums.pop(0)\n\t\t\t\telse:\n\t\t\t\t\tnum = None\n\t\t\t\tif num is not None:\n\t\t\t\t\tnode.right = TreeNode(num)\n\t\t\t\telse:\n\t\t\t\t\tnode.right = num\n\t\t\t\tself.queue.append(node.left)\n\t\t\t\tself.queue.append(node.right)\n\t\treturn self.root\nclass Solution(object):\n\tdef __init__(self):\n\t\tself.first = self.second = None\n\t\tself.pre = TreeNode(-sys.maxsize - 1)\n\tdef recoverTree(self, root):\n\t\tlength = len(root)\n\t\troot = List2Tree(root).convert()\n\t\tself.traverse(root)\n\t\tself.first.val, self.second.val = self.second.val, self.first.val\n\t\treturn root.to_list(length)\n\tdef traverse(self, root):\n\t\tif root is None:\n\t\t\treturn\n\t\tself.traverse(root.left)\n\t\tif self.pre.val >= root.val:\n\t\t\tif self.first is None:\n\t\t\t\tself.first = self.pre\n\t\t\tif self.first is not None:\n\t\t\t\tself.second = root\n\t\tself.pre = root\n\t\tself.traverse(root.right)\n# %%\ns = Solution()\nprint(s.recoverTree(root=[1, 3, None, None, 2]))", + "status": 1, + "keywords": "树,深度优先搜索,二叉搜索树,二叉树", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/a1439775520/article/details/104377203" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/98/98_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/98/98_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/98/98_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/leetcode/99.json b/data_backup/leetcode/99.json new file mode 100644 index 000000000..42efeaf7e --- /dev/null +++ b/data_backup/leetcode/99.json @@ -0,0 +1,24 @@ +{ + "question_id": 100, + "question_title": "相同的树", + "difficulty": "简单", + "question_content": "

      给你两棵二叉树的根节点 pq ,编写一个函数来检验这两棵树是否相同。

      如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。

       

      示例 1:

      \"\"
      输入:p = [1,2,3], q = [1,2,3]
      输出:
      true

      示例 2:

      \"\"
      输入:p = [1,2], q = [1,null,2]
      输出:
      false

      示例 3:

      \"\"
      输入:p = [1,2,1], q = [1,1,2]
      输出:
      false

       

      提示:

        \t
      • 两棵树上的节点数目都在范围 [0, 100]
      • \t
      • -104 <= Node.val <= 104
      ", + "topic_link": "https://bbs.csdn.net/topics/600469927", + "cpp": "#include \nusing namespace std;\nstruct TreeNode\n{\n\tint val;\n\tTreeNode *left;\n\tTreeNode *right;\n\tTreeNode() : val(0), left(nullptr), right(nullptr) {}\n\tTreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n\tTreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n};\nclass Solution\n{\npublic:\n\tbool isSameTree(TreeNode *p, TreeNode *q)\n\t{\n\t\tif (p == nullptr && q == nullptr)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\tif (p == nullptr || q == nullptr)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\tif (p->val != q->val)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\treturn isSameTree(p->left, q->left) && isSameTree(p->right, q->right);\n\t}\n};", + "java": "public class TreeNode {\n\tint val;\n\tTreeNode left;\n\tTreeNode right;\n\n\tTreeNode() {\n\t}\n\n\tTreeNode(int val) {\n\t\tthis.val = val;\n\t}\n\n\tTreeNode(int val, TreeNode left, TreeNode right) {\n\t\tthis.val = val;\n\t\tthis.left = left;\n\t\tthis.right = right;\n\t}\n}\n\nclass Solution {\n\tpublic boolean isSameTree(TreeNode p, TreeNode q) {\n\t\tif (p == null && q == null) {\n\t\t\treturn true;\n\t\t}\n\t\tif (p != null && q != null && p.val == q.val) {\n\t\t\treturn isSameTree(p.left, q.left) && isSameTree(p.right, q.right);\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n}", + "js": "", + "python": "class TreeNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.left = None\n\t\tself.right = None\nclass Solution(object):\n\tdef isSameTree(self, p, q):\n\t\t\"\"\"\n\t\t:type p: TreeNode\n\t\t:type q: TreeNode\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\tif p == q:\n\t\t\treturn True\n\t\ttry:\n\t\t\tleft = right = True\n\t\t\tif p.val == q.val:\n\t\t\t\tleft = self.isSameTree(p.left, q.left)\n\t\t\t\tright = self.isSameTree(p.right, q.right)\n\t\t\t\treturn (left and right)\n\t\texcept:\n\t\t\treturn False\n\t\treturn False\n# %%\ns = Solution()\nprint(s.isSameTree(p = [1,2,3], q = [1,2,3]))", + "status": 1, + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "license": { + "cpp": "https://github.com/begeekmyfriend/leetcode", + "python": "https://github.com/qiyuangong/leetcode", + "java": "https://blog.csdn.net/weixin_45176257/article/details/106487181" + }, + "notebook": { + "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/99/99_cpp.ipynb?type=file", + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/99/99_python.ipynb?type=file", + "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/leetcode/ipynb/99/99_java.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/0.json b/data_backup/python_code_json/0.json new file mode 100644 index 000000000..30ee4153a --- /dev/null +++ b/data_backup/python_code_json/0.json @@ -0,0 +1,18 @@ +{ + "question_id": 7434731, + "question_title": "按要求实现程序功能", + "question_content": "

      (1)定义一个函数prime判断某个整数是否为素数;\n(2)然后从键盘输入一行字符串,将其中的连续数字依次提取出来形成一个列表。例如,字符串“ab12cd34fg67”按要求提取后形成列表[12,34,67];\n(3)将列表中的所有非素数改为0(要求用prime函数判断列表中的元素是否为素 数);\n(4)输出原始字符串及修改前、修改后的列表。\n提示:可以用s.isdigit()判断s是否为数字字符(串)

      ", + "difficulty": "简单", + "answer_id": 53405170, + "answer_content": "
      \nimport math,re\n\n\n# 判断素数函数\ndef prime(num):\n\tflag = False\n\tif num > 1:\n\t\tfor i in range(2, math.floor(math.sqrt(num))):\n\t\t\tif (num % i) == 0:\n\t\t\t\tflag = True\n\t\t\t\tbreak\n\n\tif flag:\n\t\tprint(num, "不是素数")\n\telse:\n\t\tprint(num, "是素数")\n\treturn flag\n# 键盘输入字符串\ns = input("请输入字符串:")\n\n# 提取数字字符串 列表\nsList = re.findall(r'(\\d+)', s)\nsNum = [int(x) for x in sList]\n# 非素数重置为0\ny = lambda x: 0 if prime(x) else x\nsNew = [y(x) for x in sNum]\n# 输出\nprint(sNum) # 输出原列表\nprint(sNew) # 输出修改后列表
      \n\n

       

      \n", + "tag_name": "python", + "python": "import math,re\ndef prime(num):\n\tflag = False\n\tif num > 1:\n\t\tfor i in range(2, math.floor(math.sqrt(num))):\n\t\t\tif (num % i) == 0:\n\t\t\t\tflag = True\n\t\t\t\tbreak\n\tif flag:\n\t\tprint(num, \"不是素数\")\n\telse:\n\t\tprint(num, \"是素数\")\n\treturn flag\ns = input(\"请输入字符串:\")\nsList = re.findall(r'(\\d+)', s)\nsNum = [int(x) for x in sList]\ny = lambda x: 0 if prime(x) else x\nsNew = [y(x) for x in sNum]\nprint(sNum) \nprint(sNew) ", + "topic_link": "https://bbs.csdn.net/topics/600470198", + "status": 1, + "keywords": "散列表,算法中阶,数据结构,散列函数", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/0.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/1.json b/data_backup/python_code_json/1.json new file mode 100644 index 000000000..5ab948bf5 --- /dev/null +++ b/data_backup/python_code_json/1.json @@ -0,0 +1,18 @@ +{ + "question_id": 7450424, + "question_title": "输出整数的全排列", + "question_content": "输入整数n(3<=n<=7),编写程序输出1,2,....,n整数的全排列,按字典序输出。\n输入样例:\n输入:3\n输出:123 132 213 231 312 321", + "difficulty": "简单", + "answer_id": 53431109, + "answer_content": "
      \nimport random\nn = int(input())\nt = list()\nt1 = set()\nfor i in range(1,n+1):\n    t.append(str(i))\nwhile True:\n    sum = 1\n    for i in range(1, n + 1):\n        sum *= i\n    if len(t1) >= sum:\n        break\n    random.shuffle(t)\n    t1.add("".join(t))\ns = sorted(t1)\nfor i in s:\n    print(i,end=" ")
      \n\n

      \"\"

      \n\n

      记得点个采纳,谢谢 

      \n", + "tag_name": "python", + "python": "import random\nn = int(input())\nt = list()\nt1 = set()\nfor i in range(1,n+1):\n\tt.append(str(i))\nwhile True:\n\tsum = 1\n\tfor i in range(1, n + 1):\n\t\tsum *= i\n\tif len(t1) >= sum:\n\t\tbreak\n\trandom.shuffle(t)\n\tt1.add(\"\".join(t))\ns = sorted(t1)\nfor i in s:\n\tprint(i,end=\" \")", + "topic_link": "https://bbs.csdn.net/topics/600470295", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/1.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/10.json b/data_backup/python_code_json/10.json new file mode 100644 index 000000000..2ab5e8c0b --- /dev/null +++ b/data_backup/python_code_json/10.json @@ -0,0 +1,18 @@ +{ + "question_id": 7457826, + "question_title": "求最大公约数和最小公倍数", + "question_content": "

      输入两个数x 和y,如果x 或y 小于等于0,提示请输入正整数,求这两个数的最大公约数和最小公倍数。\n注意:可以采用欧几里得辗转相除算法来求最大公约数。最小公倍数的计算方法是两数的乘积除以两数最大公约数的结果。

      ", + "difficulty": "简单", + "answer_id": 53442305, + "answer_content": "
      \nx = int(input("输入x:"))\ny = int(input("输入y:"))\nif x <= 0 or x <= 0:\n    print("请输入正整数")\nif x < y:\n    x,y=y,x\n    v1 = x*y\n    v2 = x%y\n    while v2 != 0:\n        x=y\n        y = v2\n        v2 = x % y\n    v1 =v1/ y\n    print("最大公约数为:%d" % y)  \n    print("最小公倍数为:%d" % v1) \n
      \n\n

       

      \n", + "tag_name": "python", + "python": "x = int(input(\"输入x:\"))\ny = int(input(\"输入y:\"))\nif x <= 0 or y <= 0:\n\tprint(\"请输入正整数\")\nif x < y:\n\tx,y=y,x\n\tv1 = x*y\n\tv2 = x%y\n\twhile v2 != 0:\n\t\tx=y\n\t\ty = v2\n\t\tv2 = x % y\n\tv1 =v1/ y\n\tprint(\"最大公约数为:%d\" % y) \n\tprint(\"最小公倍数为:%d\" % v1) ", + "topic_link": "https://bbs.csdn.net/topics/600469983", + "status": 1, + "keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/10.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/11.json b/data_backup/python_code_json/11.json new file mode 100644 index 000000000..d4461aa8f --- /dev/null +++ b/data_backup/python_code_json/11.json @@ -0,0 +1,18 @@ +{ + "question_id": 7423742, + "question_title": "实现保留3位有效数字(四舍六入五成双规则)", + "question_content": "输入:1234 输出:1234\n 12 12.0\n 4 4.00\n 0.2 0.200\n 0.32 0.320\n 1.3 1.30\n 1.235 1.24\n 1.245 1.24\n 1.2451 1.25", + "difficulty": "中等", + "answer_id": 53383866, + "answer_content": "
      \na = input()\nif '.' in a:\n    a = float(a)\n    if a*1000%10!=5:\n        a = '%.2f'%(a)\n    else:\n        if len(str(a).split(".")[1])>3:\n            a = '%.2f'%(a)\n        else:\n            if int(a*100%10%2)==1:\n                a = float('%.2f'%float(int(a*100)/100))+0.01\n            else:\n                a = '%.2f'%float(int(a*100)/100)\n    print(a)\nelse:\n    a = int(a)\n    if a>99:\n        print(a)\n    else:\n        print(float(a))
      \n\n

       

      ", + "tag_name": "python", + "python": "a = input()\nif '.' in a:\n\ta = float(a)\n\tif a*1000%10!=5:\n\t\ta = '%.2f'%(a)\n\telse:\n\t\tif len(str(a).split(\".\")[1])>3:\n\t\t\ta = '%.2f'%(a)\n\t\telse:\n\t\t\tif int(a*100%10%2)==1:\n\t\t\t\ta = float('%.2f'%float(int(a*100)/100))+0.01\n\t\t\telse:\n\t\t\t\ta = '%.2f'%float(int(a*100)/100)\n\tprint(a)\nelse:\n\ta = int(a)\n\tif a>99:\n\t\tprint(a)\n\telse:\n\t\tif 0 < a < 10: \n\t\t\tprint('%.2f'%a)\n\t\telse:\n\t\t\tprint(float(a))", + "topic_link": "https://bbs.csdn.net/topics/600469884", + "status": 1, + "keywords": "数学,算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/11.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/12.json b/data_backup/python_code_json/12.json new file mode 100644 index 000000000..64542406c --- /dev/null +++ b/data_backup/python_code_json/12.json @@ -0,0 +1,18 @@ +{ + "question_id": 1005354, + "question_title": "随机生成车牌号", + "question_content": "

      某市随机生成车辆号牌的规则是:号牌字头为\"某A-\",\"某B-\"等(字母为除了C以外的A~H范围内的大写字母),字头后面由5位字符组成,第1位必须是数字;第2、3、4、5位可以是任意数字或不含字母\"O\"的大写英文字母。\n程序功能为:调用自己设计的函数license_plate(),随机生成5个车辆号牌,等待输入一个心仪号码的序号选择号牌,并将其打印输出。\n程序运行结果如下图所示:\n![图片说明](https://img-ask.csdn.net/upload/201912/08/1575761967_651946.jpg)

      ", + "difficulty": "简单", + "answer_id": 1186938, + "answer_content": "\n```\nimport random\ndef genrndchar(metachar):\n\treturn metachar[int(random.random() * len(metachar))]\ndef license_plate():\n\ts = \"某\"\n\ts = s + genrndchar(['A', 'B', 'C', 'D', 'E', 'H'])\n\ts = s + '-'\n\ts = s + genrndchar(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])\n\tfor i in range(4):\n\t\ts = s + genrndchar(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])\n\treturn s\n\nlst = []\nfor i in range(5):\n\tplate = license_plate()\n\tlst.append(plate)\n\tprint(str(i + 1) + \":\" + plate)\nx = int(input(\"请输入您心仪的号牌序号:\")) - 1\nprint(\"您选中的号牌为:\" + lst[x])\n```", + "tag_name": "python", + "python": "import random\ndef genrndchar(metachar):\n\treturn metachar[int(random.random() * len(metachar))]\ndef license_plate():\n\ts = \"某\"\n\ts = s + genrndchar(['A', 'B', 'C', 'D', 'E', 'H'])\n\ts = s + '-'\n\ts = s + genrndchar(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])\n\tfor i in range(4):\n\t\ts = s + genrndchar(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])\n\treturn s\nlst = []\nfor i in range(5):\n\tplate = license_plate()\n\tlst.append(plate)\n\tprint(str(i + 1) + \":\" + plate)\nx = int(input(\"请输入您心仪的号牌序号:\")) - 1\nprint(\"您选中的号牌为:\" + lst[x])", + "topic_link": "https://bbs.csdn.net/topics/600470298", + "status": 1, + "keywords": "图算法,算法高阶,图的表示,基本的图算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/12.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/13.json b/data_backup/python_code_json/13.json new file mode 100644 index 000000000..854701f40 --- /dev/null +++ b/data_backup/python_code_json/13.json @@ -0,0 +1,17 @@ +{ + "question_id": 7441321, + "question_title": "学生信息读写", + "question_content": "

      包含方法:动态输入学生信息,展示信息。
      \n2.设计功能1,能将学生对象的信息写入二进制文件,
      \n3.设计功能2,能从二进制文件中读出学生信息,展示出来。
      \n4.设计功能3,能从二进制文件中读出学生信息,转换成csv格式并保存到文件
      \n5.设计功能4,能从二进制文件中读出学生信息,转换成json格式并保存到文件
      \n6.设计功能5,能从csv文件中读出学生信息,展示,并保存到二进制文件
      \n7.设计功能6,能从json文件中读出学生信息,展示,并保存到二进制文件
      \n8.以上功能可以由多个代码文件实现

      ", + "difficulty": "中等", + "answer_id": 53417409, + "answer_content": "
      \nclass stu:\n    def __init__(self, id=1, name='Tom', grades='class1', result=100, address='CN', phone='110'):\n        self.id = id\n        self.name = name\n        self.grades = grades\n        self.result = result\n        self.address = address\n        self.phone = phone\n        self.data = dict(id=id, name=name, grades=grades, result=result, address=address, phone=phone)\n\n    def write_file(self):\n        """功能1"""\n        f = open('data.txt', 'w', encoding='utf-8')\n        f.write(str(self.data))\n        f.close()\n\n    def read_file(self):\n        """功能2"""\n        f = open('data.txt', 'r', encoding='utf-8')\n        self.data = eval(f.read())\n        f.close()\n        print(self.data)\n\n\ns = stu()\ns.write_file()\ns.read_file()
      \n\n

      参考一下:如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢

      \n", + "tag_name": "python", + "python": "class stu:\n def __init__(self, id=1, name='Tom', grades='class1', result=100, address='CN', phone='110'):\n self.id = id\n self.name = name\n self.grades = grades\n self.result = result\n self.address = address\n self.phone = phone\n self.data = dict(id=id, name=name, grades=grades, result=result, address=address, phone=phone)\n def write_file(self):\n \"\"\"功能1\"\"\"\n f = open('data.txt', 'w', encoding='utf-8')\n f.write(str(self.data))\n f.close()\n def read_file(self):\n \"\"\"功能2\"\"\"\n f = open('data.txt', 'r', encoding='utf-8')\n self.data = eval(f.read())\n f.close()\n print(self.data)\ns = stu()\ns.write_file()\ns.read_file()\n", + "topic_link": "https://bbs.csdn.net/topics/600470403", + "status": 0, + "keywords": "算法中阶,动态规划,动态规划原理,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/13.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/14.json b/data_backup/python_code_json/14.json new file mode 100644 index 000000000..43c6895b9 --- /dev/null +++ b/data_backup/python_code_json/14.json @@ -0,0 +1,17 @@ +{ + "question_id": 7445764, + "question_title": "判断成绩是否及格", + "question_content": "
      \n# 键盘输入一个成绩:\n# 如果成绩>=60并且<80输出及格\n# 成绩>=80并且<=100输出 优\n# 成绩>=0并且<60 输出  输入成绩有误,请检查\n# 输入其他字符 输出你输入的字符不合法
      ", + "difficulty": "简单", + "answer_id": 53424594, + "answer_content": "
      \n# 如果成绩>=60并且<80输出及格\n# 成绩>=80并且<=100输出 优\n# 成绩>=0并且<60 输出  输入成绩有误,请检查\n# 输入其他字符 输出你输入的字符不合法\n\nscore = input("请输入学生的成绩:")\n\nif score.isdigit():\n    score = int(score)\n    if 0 <= score < 60:\n        print('输入成绩有误,请检查')\n    if 60 <= score < 80:\n        print('及格')\n    if 80 <= score <= 100:\n        print('优')\nelse:\n    print('你输入的字符不合法')
      \n\n

       

      \n", + "tag_name": "python", + "python": "\nscore = input(\"请输入学生的成绩:\")\nif score.isdigit():\n score = int(score)\n if 0 <= score < 60:\n print('输入成绩有误,请检查')\n if 60 <= score < 80:\n print('及格')\n if 80 <= score <= 100:\n print('优')\nelse:\n print('你输入的字符不合法')\n", + "topic_link": "https://bbs.csdn.net/topics/600470299", + "status": 0, + "keywords": "比较大小", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/14.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/15.json b/data_backup/python_code_json/15.json new file mode 100644 index 000000000..a3af7ce7f --- /dev/null +++ b/data_backup/python_code_json/15.json @@ -0,0 +1,17 @@ +{ + "question_id": 7446240, + "question_title": "利用numpy和Matplotlib在同一张纸上绘制0-1间的x**2和x**3曲线", + "question_content": "

      \"\"

      \n\n

       

      ", + "difficulty": "简单", + "answer_id": 53425485, + "answer_content": "

      \"\"

      \n\n
      \nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndata = np.linspace(0,1,1000)\nplt.title('lines')\nplt.xlabel('x')\nplt.ylabel('y')\nplt.xlim((0,1))\nplt.ylim((0,1))\nb = np.arange(0,1,0.2)\nplt.xticks(b)\nplt.yticks([0,0.5,1])\nplt.plot(data,data**2,ls='--')\nplt.plot(data,data**3,color='b')\nplt.legend(['y=x^2','y^3'])\nplt.savefig('jp.png')\nplt.show()
      \n\n

       

      \n", + "tag_name": "python", + "python": "import numpy as np\nimport matplotlib.pyplot as plt\ndata = np.linspace(0,1,1000)\nplt.title('lines')\nplt.xlabel('x')\nplt.ylabel('y')\nplt.xlim((0,1))\nplt.ylim((0,1))\nb = np.arange(0,1,0.2)\nplt.xticks(b)\nplt.yticks([0,0.5,1])\nplt.plot(data,data**2,ls='--')\nplt.plot(data,data**3,color='b')\nplt.legend(['y=x^2','y^3'])\nplt.savefig('jp.png')\nplt.show()\n", + "topic_link": "https://bbs.csdn.net/topics/600469984", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/15.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/16.json b/data_backup/python_code_json/16.json new file mode 100644 index 000000000..12dac9a42 --- /dev/null +++ b/data_backup/python_code_json/16.json @@ -0,0 +1,17 @@ +{ + "question_id": 7442242, + "question_title": "python复利计算利息", + "question_content": "

      . 编写一个程序计算10万元本金在银行以4.5%的年利息存5年后得到的收益,按复利计算利息。

      ", + "difficulty": "简单", + "answer_id": 53419050, + "answer_content": "
      \n# encoding: utf-8\n"""\n@version: 1.0\n@author: AusKa_T\n@file: 2\n@time: 2021/6/4 0004 17:30\n"""\n"""\n计算复利公式\n"""\nimport matplotlib.pyplot as plt\n# 加载字体\nimport matplotlib as mpl\n\nmpl.rcParams["font.sans-serif"] = ["KaiTi"]\nmpl.rcParams["font.serif"] = ["KaiTi"]\n\na = 100000  # 这里是本金\nr1 = 0.045\nx = []\ny1 = []\ny2 = []\ny3 = []\ny4 = []\ny5 = []\ny6 = []\n# 填入数据\nfor i in range(1, 6):\n    x.append(i)\n    y1.append(a * (1 + r1) ** i)\n\nfilename1 = "利率" + str(r1) + ".txt"\n\nwith open(filename1, "w", encoding="utf-8") as f1:\n    for i in range(1, 6):\n        f1.write(\n            "第" + str(i) + "年的本息和为:" + str(y1[i - 1]).split('.')[0] + '.' + str(y1[i - 1]).split('.')[1][:2] + "\\n")\n\n\n\n# 绘图\ntitle = "本金为" + str(a) + "的时候的复利金额"\nplt.title(title)\nplt.plot(x, y1, "b^-", label="利率为" + str(r1))\nplt.xlabel("存储年限")\nplt.ylabel("本息和")\n\n# 显示标签\nplt.legend()\n# 显示格子\nplt.grid()\n# 保存图片\nplt.savefig("复利图.PNG")\nplt.show()
      \n\n

       

      \n\n

      \"\"

      \n", + "tag_name": "python", + "python": "import matplotlib.pyplot as plt\nimport matplotlib as mpl\nmpl.rcParams[\"font.sans-serif\"] = [\"KaiTi\"]\nmpl.rcParams[\"font.serif\"] = [\"KaiTi\"]\na = 100000 \nr1 = 0.045\nx = []\ny1 = []\ny2 = []\ny3 = []\ny4 = []\ny5 = []\ny6 = []\nfor i in range(1, 6):\n\tx.append(i)\n\ty1.append(a * (1 + r1) ** i)\nfilename1 = \"利率\" + str(r1) + \".txt\"\nwith open(filename1, \"w\", encoding=\"utf-8\") as f1:\n\tfor i in range(1, 6):\n\t\tf1.write(\n\t\t\t\"第\" + str(i) + \"年的本息和为:\" + str(y1[i - 1]).split('.')[0] + '.' + str(y1[i - 1]).split('.')[1][:2] + \"\\n\")\ntitle = \"本金为\" + str(a) + \"的时候的复利金额\"\nplt.title(title)\nplt.plot(x, y1, \"b^-\", label=\"利率为\" + str(r1))\nplt.xlabel(\"存储年限\")\nplt.ylabel(\"本息和\")\nplt.legend()\nplt.grid()\nplt.savefig(\"复利图.PNG\")\nplt.show()", + "topic_link": "https://bbs.csdn.net/topics/600470500", + "status": 0, + "keywords": "算法高阶,计算几何学,算法问题选编", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/16.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/17.json b/data_backup/python_code_json/17.json new file mode 100644 index 000000000..5dc99ed04 --- /dev/null +++ b/data_backup/python_code_json/17.json @@ -0,0 +1,17 @@ +{ + "question_id": 1048722, + "question_title": "Python编写程序,对模拟打字游戏并进行成绩判定", + "question_content": "1、编写一个程序,要求该程序运行后,生成一个名为“new.py”的文件,在每一行后面添加行号,且行号以\"#\"开头,即行号为注释信息,不影响程序的正常执行。同时要求所有行的\"#\"号垂直对齐。", + "difficulty": "简单", + "answer_id": 1246232, + "answer_content": "\n```\nimport random\nimport string\n\n\nclass Game:\n def __init__(self):\n self.total_count = 0\n self.right_count = 0\n self.len = 15\n\n def play(self):\n n = int(input('请输入打字次数:'))\n while n:\n right = 0\n print('游戏次数剩余{}次'.format(n))\n word = ''.join(random.sample(string.ascii_letters + string.digits + ' ', random.randint(1, self.len)))\n print(word)\n res = input()\n if len(res) != len(word):\n print('输入的字符串超长,无效')\n self.total_count += len(word)\n n -= 1\n continue\n for i in zip(word, res):\n if i[0] == i[1]:\n right += 1\n self.right_count += right\n self.total_count += len(word)\n print('本次的正确率为{:.2f}%\\n'.format(right * 100 / len(word)))\n n -= 1\n print('整体的正确率为{:.2f}%'.format(self.right_count * 100 / self.total_count))\n\n\nif __name__ == '__main__':\n Game().play()\n\n```", + "tag_name": "python", + "python": "import random\nimport string\nclass Game:\n def __init__(self):\n self.total_count = 0\n self.right_count = 0\n self.len = 15\n def play(self):\n n = int(input('请输入打字次数:'))\n while n:\n right = 0\n print('游戏次数剩余{}次'.format(n))\n word = ''.join(random.sample(string.ascii_letters + string.digits + ' ', random.randint(1, self.len)))\n print(word)\n res = input()\n if len(res) != len(word):\n print('输入的字符串超长,无效')\n self.total_count += len(word)\n n -= 1\n", + "topic_link": "https://bbs.csdn.net/topics/600469985", + "status": 0, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/17.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/18.json b/data_backup/python_code_json/18.json new file mode 100644 index 000000000..86db659b4 --- /dev/null +++ b/data_backup/python_code_json/18.json @@ -0,0 +1,18 @@ +{ + "question_id": 7462191, + "question_title": "python 编程 猜数字", + "question_content": "

      游戏(猜数字):随机生成一个数字(取值范围[1,100])。让用户猜数字,并给出相应的提示:\n如果用户输入比答案大,提示‘Too big, try again’;\n反之,提示‘Too small, try again’;\n如果猜中了,提示‘Congratulations!’。\n最后,要给出反馈(答案,猜的次数,猜的历史)。\n 

      ", + "difficulty": "简单", + "answer_id": 53447630, + "answer_content": "

      \"\"

      \n\n
      \nimport random\n\nv=random.randint(1,100)\n\ncount=0\nhis=[]\nwhile 1:\n    vi=input("输入猜测值:")\n    count+=1\n    his.append(vi)\n    if int(vi)>v:\n        print("Too big,try again")\n    if int(vi)<v:\n        print("Too small,try again")\n    if int(vi)==v:\n        print('Congratulations!')\n        break\n\nprint("答案是:%d" % v)\nprint("猜测次数:%d" % count)\nst=''\nfor i in his:\n    st+=i\n    st+=','\nst=st[:-1]\nprint("猜测历史:%s" % st)\n\n
      \n\n

       

      \n", + "tag_name": "python", + "python": "import random\nv=random.randint(1,100)\ncount=0\nhis=[]\nwhile 1:\n\tvi=input(\"输入猜测值:\")\n\tcount+=1\n\this.append(vi)\n\tif int(vi)>v:\n\t\tprint(\"Too big,try again\")\n\tif int(vi)如果用户选择菜单选项1,提示用户输入1到10之间的整数,并打印一个乘法表,显示整数1与输入整数相乘的结果,如下面的示例所示。注意:不需要检查输入的数字是否在1到10之间。如果用户选择菜单选项2,退出程序。如果用户在菜单选择中输入了1或2以外的任何内容,输出信息“菜单选择错误,请重试并继续程序。”\n结果应该如下:\n1)创建乘法表\n2)退出程序\n请从以上菜单中选择一个选项:1\n输入一个介于1到10之间的整数:3

      \n

      1  2  3 

      \n

      2  4  6 

      \n

      3  6  9 

      \n

       \n1)创建乘法表\n2)退出程序\n请从以上菜单中选择一个选项:4\n菜单选择错误,请重试\n \n1)创建乘法表\n2)退出程序\n请从以上菜单中选择一个选项:2\n谢谢你使用乘法表\n \n 

      \n

       

      ", + "difficulty": "简单", + "answer_id": 53385987, + "answer_content": "
      \nwhile True:\n    print('1)创建乘法表')\n    print('2)退出程序')\n    n = input('请从以上菜单中选择一个选项:').strip()\n    if n=='1':\n        x = int(input('输入一个介于1到10之间的整数:'))\n        for i in range(1,x+1):\n            for j in range(1,x+1):\n                print("{:>4}".format(i*j),end="")\n            print()\n    elif n=='2':\n        print('谢谢你使用乘法表')\n        break\n    else:\n        print('菜单选择错误,请重试')\n    print('-----------------------------')\n
      \n\n

      \"\"

      ", + "tag_name": "python", + "python": "while True:\n\tprint('1)创建乘法表')\n\tprint('2)退出程序')\n\tn = input('请从以上菜单中选择一个选项:').strip()\n\tif n=='1':\n\t\tx = int(input('输入一个介于1到10之间的整数:'))\n\t\tfor i in range(1,x+1):\n\t\t\tfor j in range(1,x+1):\n\t\t\t\tprint(\"{:>4}\".format(i*j),end=\"\")\n\t\t\tprint()\n\telif n=='2':\n\t\tprint('谢谢你使用乘法表')\n\t\tbreak\n\telse:\n\t\tprint('菜单选择错误,请重试')\n\tprint('-----------------------------')", + "topic_link": "https://bbs.csdn.net/topics/600469886", + "status": 1, + "keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/19.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/2.json b/data_backup/python_code_json/2.json new file mode 100644 index 000000000..9d2d835a6 --- /dev/null +++ b/data_backup/python_code_json/2.json @@ -0,0 +1,17 @@ +{ + "question_id": 7455330, + "question_title": "Python团队出行财务系统管理", + "question_content": "

      假设有N个人出行,期间会产生交通费(A)、餐费(B)、住宿费(C)三种类型的费用,设计并实现团体出行期间的财务管理系统,能够根据每笔账单的信息,最终计算出在此次出行中,每个人的花销。

      \n\n

      系统运行时,先输入出行人数N的值。随后给出2个菜单,菜单1代表输入账单,菜单2代表计算每个人的花销。1.输入的账单信息时,先输入该笔账单参与的人数M,再输入涉及到的M个成员的代号(从1-N),账单类别(A、B、C三者之一),及金额。2.计算每个人最终花销时,根据账单采用AA制的方式。

      ", + "difficulty": "中等", + "answer_id": 53438235, + "answer_content": "
      \np = int(input('出行人数:'))\nprint('成员代号为:', [i for i in range(1, p+1)])\nd = {}\nr = []\nm = input('账单记录输入1,计算花销输入2')\nif m == '1':\n    n = int(input('参与人数:'))\n    pl = ''\n    for i in range(n):\n        pl += input('成员代号:')\n    d['pl'] = pl\n    d['style'] = input('账单类别,输入a、b、c:')\n    d['money'] = int(input('账单金额:'))\n    r.append(d)\nelif m == '2':\n    for i in r:\n        avg = d['money'] / len(d['pl'])\n        print(f"成员代号:{len(d['pl'])},每人平均费用:{avg},账单类型:{d['style']}")\n
      \n\n

      如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢

      \n", + "tag_name": "python", + "python": "p = int(input('出行人数:'))\nprint('成员代号为:', [i for i in range(1, p+1)])\nd = {}\nr = []\nm = input('账单记录输入1,计算花销输入2')\nif m == '1':\n n = int(input('参与人数:'))\n pl = ''\n for i in range(n):\n pl += input('成员代号:')\n d['pl'] = pl\n d['style'] = input('账单类别,输入a、b、c:')\n d['money'] = int(input('账单金额:'))\n r.append(d)\nelif m == '2':\n for i in r:\n avg = d['money'] / len(d['pl'])\n print(f\"成员代号:{len(d['pl'])},每人平均费用:{avg},账单类型:{d['style']}\")\n", + "topic_link": "https://bbs.csdn.net/topics/600469883", + "status": 0, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/2.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/20.json b/data_backup/python_code_json/20.json new file mode 100644 index 000000000..fbef9a67a --- /dev/null +++ b/data_backup/python_code_json/20.json @@ -0,0 +1,18 @@ +{ + "question_id": 7457794, + "question_title": "找出素数对", + "question_content": "任意输入一个大于10的偶数编程找出所有和等于该偶数的素数对", + "difficulty": "简单", + "answer_id": 53442307, + "answer_content": "
      \nh = 0\n\ndef a(h):\n    x = 0\n    for j in range(2, h):\n        if h % j == 0:\n            x = 1\n            break\n\n    if x == 0:\n        return 1\n\nn = int(input("输入任意大于10的偶数:"))\nfor i in range(n,n+1):\n    h = 0\n    if i % 2 == 0:\n        for k in range(2, i):\n            if a(k) == 1 and a(i - k) == 1:\n                h = 1\n                if h == 0:\n                    print("%d can't" % i)\n                    break\n                else:\n                    print("%d=%d+%d" % (i, k, i - k))\n                    break\n
      \n\n

      参考这个:https://blog.csdn.net/edxuanlen/article/details/78336429?utm_source=blogxgwz5&utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-1&spm=1001.2101.3001.4242

      \n", + "tag_name": "python", + "python": "h = 0\ndef a(h):\n\tx = 0\n\tfor j in range(2, h):\n\t\tif h % j == 0:\n\t\t\tx = 1\n\t\t\tbreak\n\tif x == 0:\n\t\treturn 1\nn = int(input(\"输入任意大于10的偶数:\"))\nfor i in range(n,n+1):\n\th = 0\n\tif i % 2 == 0:\n\t\tfor k in range(2, i):\n\t\t\tif a(k) == 1 and a(i - k) == 1:\n\t\t\t\th = 1\n\t\t\t\tif h == 0:\n\t\t\t\t\tprint(\"%d can't\" % i)\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tprint(\"%d=%d+%d\" % (i, k, i - k))\n\t\t\t\t\tbreak", + "topic_link": "https://bbs.csdn.net/topics/600470404", + "status": 1, + "keywords": "算法高阶,数论算法,素数的测试,算法问题选编", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/20.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/21.json b/data_backup/python_code_json/21.json new file mode 100644 index 000000000..d3b987c1f --- /dev/null +++ b/data_backup/python_code_json/21.json @@ -0,0 +1,18 @@ +{ + "question_id": 1089095, + "question_title": "将一组数尽可能均匀地分成两堆,使两个堆中的数的和尽可能相等", + "question_content": "

      麦克叔叔去世了,他在遗嘱中给他的两个孙子阿贝和鲍勃留下了一堆珍贵的口袋妖怪卡片。遗嘱中唯一的方向是“尽可能均匀地分配纸牌的价值”。作为Mike遗嘱的执行人,你已经为每一张口袋妖怪卡片定价,以获得准确的货币价值。你要决定如何将口袋妖怪卡片分成两堆,以尽量减少每一堆卡片的价值总和的差异。\n例如,你有下列n=8 个口袋妖怪卡片:\n![图片说明](https://img-ask.csdn.net/upload/202006/27/1593264517_917706.png)\n经过大量的工作,你发现你可以用下面的方法来划分卡片:\n![图片说明](https://img-ask.csdn.net/upload/202006/27/1593264556_309804.png)\n这给了安倍10美元的牌给了鲍勃11美元的牌。这是最好的除法吗?\n你要做的是解决n张牌的问题其中每张牌ci都有一个正整数值vi.你的解决方法是计算牌应该如何被分割以及每摞牌的价值。\n输入输出示例如下:\n![图片说明](https://img-ask.csdn.net/upload/202006/27/1593264585_763892.png)\n1.通过检查所有可能的桩以蛮力解决此问题。 对这种蛮力算法的时间复杂度进行分析,并通过实施和实验验证您的分析结果(既写出来算法的设计思路等),并用python算法实现编程\n2.通过动态编程开发更有效的算法。 您应该首先通过动态编程的思想来分析此问题,并编写相应的递归属性。 对这种算法的时间复杂度进行分析,并通过实施和实验验证您的分析结果。并用python代码实现动态编程

      ", + "difficulty": "中等", + "answer_id": 1295967, + "answer_content": "\n```\ndef deal(data,flag):\n a=[]\n for i in data:\n if i>=flag:\n return [i]\n elif a==[]:\n a.append([i])\n else:\n a=a+[k+[i] for k in a if sum(k)+i<=flag]\n a.append([i])\n #return sorted(a,key=sum)[-1]\n target=sum(max(a,key=sum))\n return list(filter(lambda x:sum(x)==target,a))\nif __name__=='__main__':\n c=[2,1,3,1,5,2,3,4]\n flag=sum(c)//2\n res=deal(c,flag)\n print(res)\n\n```\n\n算法复杂度最差是N的3次方", + "tag_name": "python", + "python": "def deal(data,flag):\n\ta=[]\n\tfor i in data:\n\t\tif i>=flag:\n\t\t\treturn [i]\n\t\telif a==[]:\n\t\t\ta.append([i])\n\t\telse:\n\t\t\ta=a+[k+[i] for k in a if sum(k)+i<=flag]\n\t\t\ta.append([i])\n\ttarget=sum(max(a,key=sum))\n\treturn list(filter(lambda x:sum(x)==target,a))\nif __name__=='__main__':\n\tc=[2,1,3,1,5,2,3,4]\n\tflag=sum(c)//2\n\tres=deal(c,flag)\n\tprint(res)", + "topic_link": "https://bbs.csdn.net/topics/600469887", + "status": 1, + "keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/21.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/22.json b/data_backup/python_code_json/22.json new file mode 100644 index 000000000..e2e7295a4 --- /dev/null +++ b/data_backup/python_code_json/22.json @@ -0,0 +1,18 @@ +{ + "question_id": 7425360, + "question_title": "任意多行字符串拆分数值求和", + "question_content": "

      编写程序,统计每行字符串中若干整数的和。每行字符串中整数间的分隔符可能有逗号“,”、分号“ ;”和空格,有多少行就求多少行。\n输入格式:\n任意输入若干行由整数构成的字符串(回车换行),整数间以逗号或空格或分号分隔。测试数确保至少有一行数据,字符串中的整数数据均合法有效。最后以一个回车结束输入。\n输出格式:\n对应输出原输入串(一行中的字符序列),冒号后输出各个整数之和。\n

      输入样例:

      \n
      \n1; 2 ,3\n2 3; 4\n10,20 30; 40\n 9
      \n

      输出样例:

      \n
      \n1; 2 ,3:6\n2 3; 4:9\n10,20 30; 40:100
      ", + "difficulty": "简单", + "answer_id": 53386858, + "answer_content": "
      \n# s = """1; 2 ,3\n# 2 3; 4\n# 10,20 30; 40\n# 9"""\n\nstopword = ''  # 修改输入终止符为空行\n\ns = ''\n\nprint('请输入内容,输入空行回车结束输入:')\n\nfor line in iter(input, stopword):\n    s = s + line + "\\n"\n\nprint(s)\n\nl = s.splitlines()\nfor num in range(0, len(l)):\n    one = l[num].replace(',', ' ').replace(';', ' ').split()\n    onesum = 0\n    for i in range(0, len(one)):\n        onesum = onesum + int(one[i])\n    print(l[num] + ":" + str(onesum))\n
      \n\n

       

      ", + "tag_name": "python", + "python": "stopword = '' \ns = ''\nprint('请输入内容,输入空行回车结束输入:')\nfor line in iter(input, stopword):\n\ts = s + line + \"\\n\"\nprint(s)\nl = s.splitlines()\nfor num in range(0, len(l)):\n\tone = l[num].replace(',', ' ').replace(';', ' ').split()\n\tonesum = 0\n\tfor i in range(0, len(one)):\n\t\tonesum = onesum + int(one[i])\n\tprint(l[num] + \":\" + str(onesum))", + "topic_link": "https://bbs.csdn.net/topics/600470501", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/22.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/23.json b/data_backup/python_code_json/23.json new file mode 100644 index 000000000..b1c6500e7 --- /dev/null +++ b/data_backup/python_code_json/23.json @@ -0,0 +1,17 @@ +{ + "question_id": 7456975, + "question_title": "五星好评点评器", + "question_content": "运用Python制作五星好评点评器", + "difficulty": "简单", + "answer_id": 53441583, + "answer_content": "

       

      \n\n

       

      \n\n

      大概吧# 也不知道你要的结果是什么。

      \n\n

       

      \n\n

       

      \n\n
      \nimport sys\nfrom PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QGroupBox\nclass Windows(QWidget):\n    def __init__(self):\n        super().__init__()\n        self.resize(500, 400)\n        self.setWindowTitle('好评点评器')\n        self.butt()\n\n    def butt(self):\n        self.button = QPushButton(self)\n        self.button.setText('python')\n        self.button.resize(100, 70)\n        self.button1 = QPushButton(self)\n        self.button1.setText('C')\n        self.button1.resize(100, 70)\n        self.button1.move(100, 0)\n        self.button2 = QPushButton(self)\n        self.button2.setText('C++')\n        self.button2.resize(100, 70)\n        self.button2.move(200, 0)\n        self.button3 = QPushButton(self)\n        self.button3.setText('C#')\n        self.button3.resize(100, 70)\n        self.button3.move(300, 0)\n        self.button4 = QPushButton(self)\n        self.button4.setText('JAVA')\n        self.button4.resize(100, 70)\n        self.button4.move(400, 0)\n        self.box = QGroupBox('评论', self)  # 分组线\n        self.box.move(10, 80)\n        self.box.resize(200, 100)\n        self.box1 = QGroupBox('我的评论', self)  # 分组线\n        self.box1.move(220, 80)\n        self.box1.resize(200, 100)\n        self.qlbel = QLabel(self.box)\n        self.qlbel.setText('非常好,简单易学')\n        self.qlbel.move(20, 30)\n        self.qlbel1 = QLabel(self.box)\n        self.qlbel1.setText('★★★★☆')\n        self.qlbel1.move(20, 70)\n        self.qlbel1.setStyleSheet(' color: #FF4500;')\n\n\n\nif __name__ == '__main__':\n    app = QApplication(sys.argv)\n    windows = Windows()\n    windows.show()\n    sys.exit(app.exec_())\n
      \n", + "tag_name": "python", + "python": "import sys\nfrom PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QGroupBox\nclass Windows(QWidget):\n def __init__(self):\n super().__init__()\n self.resize(500, 400)\n self.setWindowTitle('好评点评器')\n self.butt()\n def butt(self):\n self.button = QPushButton(self)\n self.button.setText('python')\n self.button.resize(100, 70)\n self.button1 = QPushButton(self)\n self.button1.setText('C')\n self.button1.resize(100, 70)\n self.button1.move(100, 0)\n self.button2 = QPushButton(self)\n self.button2.setText('C++')\n self.button2.resize(100, 70)\n self.button2.move(200, 0)\n self.button3 = QPushButton(self)\n self.button3.setText('C#')\n self.button3.resize(100, 70)\n self.button3.move(300, 0)\n self.button4 = QPushButton(self)\n self.button4.setText('JAVA')\n self.button4.resize(100, 70)\n self.button4.move(400, 0)\n self.box = QGroupBox('评论', self) # 分组线\n self.box.move(10, 80)\n self.box.resize(200, 100)\n self.box1 = QGroupBox('我的评论', self) # 分组线\n self.box1.move(220, 80)\n self.box1.resize(200, 100)\n self.qlbel = QLabel(self.box)\n self.qlbel.setText('非常好,简单易学')\n self.qlbel.move(20, 30)\n self.qlbel1 = QLabel(self.box)\n self.qlbel1.setText('★★★★☆')\n self.qlbel1.move(20, 70)\n self.qlbel1.setStyleSheet(' color: #FF4500;')\nif __name__ == '__main__':\n app = QApplication(sys.argv)\n windows = Windows()\n windows.show()\n sys.exit(app.exec_())\n", + "topic_link": "https://bbs.csdn.net/topics/600469888", + "status": 0, + "keywords": "点评器", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/23.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/24.json b/data_backup/python_code_json/24.json new file mode 100644 index 000000000..6feb69ba9 --- /dev/null +++ b/data_backup/python_code_json/24.json @@ -0,0 +1,17 @@ +{ + "question_id": 7447154, + "question_title": "文件检索", + "question_content": "

      1、从键盘输入字符串至str,输入路径至findpath,检索并列出findpath中所有含有str的文件名及所在路径;

      \n\n

      2、将检索到的前5个文件复制到某个指定的目录中。

      ", + "difficulty": "简单", + "answer_id": 53426675, + "answer_content": "
      \nimport os\nimport shutil\n\nstr = input('输入字符串:')\nfindpath = r'e:\\xxx'\n\ndef listdir(path, list_name):  #传入存储的list\n    for file in os.listdir(path):\n        file_path = os.path.join(path, file)\n        if os.path.isdir(file_path):\n            listdir(file_path, list_name)\n        else:\n            list_name.append(file_path)\n\nflist = []\nlistdir(findpath, flist)\nflist = [x for x in flist if x.find(str)!=-1]\nprint(*flist,sep='\\n')\npath2 = r'e:\\xxx2'\nfor x in flist[:5]:\n    shutil.copy(x,path2)\n
      \n\n

       

      \n", + "tag_name": "python", + "python": "import os\nimport shutil\nstr = input('输入字符串:')\nfindpath = r'e:\\xxx'\ndef listdir(path, list_name): \n for file in os.listdir(path):\n file_path = os.path.join(path, file)\n if os.path.isdir(file_path):\n listdir(file_path, list_name)\n else:\n list_name.append(file_path)\nflist = []\nlistdir(findpath, flist)\nflist = [x for x in flist if x.find(str)!=-1]\nprint(*flist,sep='\\n')\npath2 = r'e:\\xxx2'\nfor x in flist[:5]:\n shutil.copy(x,path2)\n", + "topic_link": "https://bbs.csdn.net/topics/600469889", + "status": 0, + "keywords": "图算法,算法高阶,单源最短路径,差分约束和最短路径", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/24.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/25.json b/data_backup/python_code_json/25.json new file mode 100644 index 000000000..145a4b57c --- /dev/null +++ b/data_backup/python_code_json/25.json @@ -0,0 +1,18 @@ +{ + "question_id": 7439730, + "question_title": "冒泡排序", + "question_content": "

      用冒泡排序编写一个函数,允许接受多个数字的输入,不使用sort方法,给数字从小到大排序,最终输出从小到大的列表。

      ", + "difficulty": "简单", + "answer_id": 53414504, + "answer_content": "

       你要的python版本,它来了

      \n\n
      \n#!/usr/bin/python3\n\n\ndef bubbleSort(arr):\n    n = len(arr)\n \n    # 遍历所有数组元素\n    for i in range(n):\n \n        # Last i elements are already in place\n        for j in range(0, n-i-1):\n \n            if arr[j] > arr[j+1] :\n                arr[j], arr[j+1] = arr[j+1], arr[j]\n\n\nx=input("请输入数字,空格分隔:")\nxlist=x.split(" ")\narr = [int(xlist[i]) for i in range(len(xlist))]\nbubbleSort(arr)\n \nprint ("排序后的数组:")\nfor i in range(len(arr)):\n    print ("%d" %arr[i]),
      \n\n

      \"\"

      \n", + "tag_name": "python", + "python": "#!/usr/bin/python3\ndef bubbleSort(arr):\n\tn = len(arr)\n\tfor i in range(n):\n\t\tfor j in range(0, n-i-1):\n\t\t\tif arr[j] > arr[j+1] :\n\t\t\t\tarr[j], arr[j+1] = arr[j+1], arr[j]\nx=input(\"请输入数字,空格分隔:\")\nxlist=x.split(\" \")\narr = [int(xlist[i]) for i in range(len(xlist))]\nbubbleSort(arr)\nprint (\"排序后的数组:\")\nfor i in range(len(arr)):\n\tprint (\"%d\" %arr[i]),", + "topic_link": "https://bbs.csdn.net/topics/600469986", + "status": 1, + "keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/25.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/26.json b/data_backup/python_code_json/26.json new file mode 100644 index 000000000..9e9226b3f --- /dev/null +++ b/data_backup/python_code_json/26.json @@ -0,0 +1,17 @@ +{ + "question_id": 7461537, + "question_title": "线性回归", + "question_content": "

      把以下数据制作成csv数据文件,并命名为LR_data_exam.csv。 
      \n对该文件内的数据进行线性回归
      \n画出数据的散点图
      \n建立线性回归模型并拟合
      \n打印拟合结果(参数) 
      \n画出数据和拟合直线的图
      \n用model.predict预测x为10,20,30时的结果
      \n用拟合参数预测x为40,50,60时的结果
      \n   battery,KM
      \n   2,12
      \n   5,31
      \n   8,45
      \n   8,52
      \n   13,79
      \n   15,85
      \n   17,115
      \n   19,119
      \n   21,135
      \n   24,145

      ", + "difficulty": "简单", + "answer_id": 53446955, + "answer_content": "
      \nimport numpy as np\nimport csv\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.linear_model import LinearRegression\nimport matplotlib\nmatplotlib.rcParams['font.sans-serif'] = ['SimHei']\nmatplotlib.rcParams['font.family']=['sans-serif']\n\ndata = '''battery,KM\n   2,12\n   5,31\n   8,45\n   8,52\n   13,79\n   15,85\n   17,115\n   19,119\n   21,135\n   24,145'''.split('\\n')\nfor i,j in enumerate(data):\n    data[i] = j.replace(' ', '').split(',')\n\nwith  open('LR_data_exam.csv','w') as csvFile: #一行一行地写入到csv文件中\n    writer = csv.writer(csvFile)\n    #先写columns_name\n    writer.writerow(data[0])\n    #写入多行用writerows\n    writer.writerows(data[1:])
      \n\n

       LR_data_exam.csv:

      \n\n

      \"\"

      \n\n
      \ndataframe = pd.read_csv("LR_data_exam.csv", sep=",")\nx = dataframe['battery'].tolist()\ny = dataframe['KM'].tolist()\n\n# 画出数据的散点图\nfig = plt.figure()\nfig.set_size_inches(10, 4)   # 整个绘图区域的宽度10和高度4\nax = fig.add_subplot(1, 2, 1)  # 整个绘图区分成一行两列,当前图是第一个。\n# 画出原始数据的散点图。\nax.set_title("散点图")\nax.set_xlabel("battery")\nax.set_ylabel("KM")\nax.scatter(x, y)\nplt.show()
      \n\n

      \"\"

      \n\n
      \nregressor = LinearRegression()\nregressor = regressor.fit(np.reshape(x,(-1, 1)),np.reshape(y,(-1, 1)))\nprint(regressor.coef_, regressor.intercept_)  # 打印拟合结果(参数)
      \n\n
      \n[[6.28763667]] [-1.19680404]
      \n\n
      \n# 画出数据和拟合直线的图\nplt.scatter(x, y)\nplt.plot(np.reshape(x,(-1,1)), regressor.predict(np.reshape(x,(-1,1))))\nplt.xlabel("battery") \nplt.ylabel("KM") \nplt.title("拟合结果")\nplt.show()
      \n\n

      \"\"

      \n\n
      \nprint(regressor.predict([[10], [20], [30]]))  # model.predict预测x为10,20,30时的结果\nfor i in [40,50,60]:\n    print(regressor.coef_*i + regressor.intercept_)   #用拟合参数预测x为40,50,60时的结果
      \n\n
      \n[[ 61.67956266]\n [124.55592935]\n [187.43229605]]\n[[250.30866274]]\n[[313.18502944]]\n[[376.06139613]]
      \n", + "tag_name": "python", + "python": "import numpy as np\nimport csv\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.linear_model import LinearRegression\nimport matplotlib\nmatplotlib.rcParams['font.sans-serif'] = ['SimHei']\nmatplotlib.rcParams['font.family']=['sans-serif']\ndata = '''battery,KM\n 2,12\n 5,31\n 8,45\n 8,52\n 13,79\n 15,85\n 17,115\n 19,119\n 21,135\n 24,145'''.split('\\n')\nfor i,j in enumerate(data):\n data[i] = j.replace(' ', '').split(',')\nwith open('LR_data_exam.csv','w') as csvFile: \n writer = csv.writer(csvFile)\n writer.writerow(data[0])\n writer.writerows(data[1:])\n", + "topic_link": "https://bbs.csdn.net/topics/600470502", + "status": 0, + "keywords": "图算法,算法高阶,图的表示,基本的图算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/26.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/27.json b/data_backup/python_code_json/27.json new file mode 100644 index 000000000..6c5592363 --- /dev/null +++ b/data_backup/python_code_json/27.json @@ -0,0 +1,18 @@ +{ + "question_id": 7458855, + "question_title": "统计成绩分布", + "question_content": "

      随机产生10个[0,100]之间的整数,模拟5名学生的考试成绩。\n要求:输出成绩,计算平均分,统计高于平均分的人数

      ", + "difficulty": "简单", + "answer_id": 53443612, + "answer_content": "

      用random函数就行,然后再遍历,输出,求平均分

      \n\n
      \nimport random\na=[]\nsum=0\ncnt=0\nfor i in range(10):\n    x=random.randint(10,100)\n    sum+=x\n    print(x,end=" ")\n    a.append(x)\nave=sum/10\nprint()\nprint(ave)\nfor i in range(10):\n    if a[i]>ave:\n        cnt+=1\nprint(cnt)\n
      \n\n

      \"\"

      \n\n

      如果有帮助请点一下我回答右上方的采纳,谢谢!以后有什么问题可以互相交流。 

      \n", + "tag_name": "python", + "python": "import random\na=[]\nsum=0\ncnt=0\nfor i in range(10):\n\tx=random.randint(0,100)\n\tsum+=x\n\tprint(x,end=\" \")\n\ta.append(x)\nave=sum/10\nprint()\nprint(ave)\nfor i in range(10):\n\tif a[i]>ave:\n\t\tcnt+=1\nprint(cnt)", + "topic_link": "https://bbs.csdn.net/topics/600470405", + "status": 1, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/27.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/28.json b/data_backup/python_code_json/28.json new file mode 100644 index 000000000..7aa9f5ccf --- /dev/null +++ b/data_backup/python_code_json/28.json @@ -0,0 +1,17 @@ +{ + "question_id": 7440964, + "question_title": "按要求实现程序功能", + "question_content": " 第一题:\n \n \n 给定公司N名员工的工龄,要求按工龄增序输出每个工龄段有多少员工。\n \n \n 输入格式:\n \n \n 输入首先给出正整数N(≤10​5​​),即员工总人数;随后给出N个整数,即每个员工的工龄,范围在[0, 50]。\n \n \n 输出格式:\n \n \n 按工龄的递增顺序输出每个工龄的员工个数,格式为:“工龄:人数”。每项占一行。如果人数为0则不输出该项。\n \n \n 输入样例:\n \n \n 8\n10 2 0 5 7 2 5 2 \n \n 输出样例:\n \n \n 0:1\n2:3\n5:2\n7:1\n10:1 \n \n 第二题:\n \n \n 编写程序,统计每行字符串中若干整数的和。每行字符串中整数间的分隔符可能有逗号“,”、分号“ ;”和空格,有多少行就求多少行。\n \n \n 输入格式:\n \n \n 任意输入若干行由整数构成的字符串(回车换行),整数间以逗号或空格或分号分隔。测试数确保至少有一行数据,字符串中的整数数据均合法有效。最后以一个回车结束输入。\n \n \n 输出格式:\n \n \n 对应输出原输入串(一行中的字符序列),冒号后输出各个整数之和。\n \n \n 输入样例:\n \n \n 1; 2 ,3\n2 3; 4\n10,20 30; 40\n 9 \n \n 输出样例:\n \n \n 1; 2 ,3:6\n2 3; 4:9\n10,20 30; 40:100\n 9:9 ", + "difficulty": "中等", + "answer_id": 53416676, + "answer_content": "

      这样修改即可:

      \n\n
      \n第一题:\na=int(input())\nb=map(int,input().split())\nc={}\nfor i in b:\n    if i in c:\n        c[i]+=1  #键存在就加1\n    else:\n        c[i]=1   #而键不存在就c[i]=1\n\nfor i in sorted(c.items(),key=lambda x:x[0]):  #字典排序(按工龄的递增顺序输出每个工龄的员工个数)\n    print('{}:{}'.format(i[0],i[1]))\n\n#第二题\n\nnum=[]\nns=[]\nwhile True:\n    n = input()  \n    if n == '':\n        break\n    else:\n        num .append(n.replace(';', ' ').replace(',', ' ').split())\n        ns.append(n)\ntry:\n    for a,b in zip(num,ns):\n        result=0\n        for i in a:\n            result += int(i)\n        print(b+f':{result}')\n\nexcept:\n    print('divided by zero')
      \n\n

      如满意解答,请点采纳。 

      \n", + "tag_name": "python", + "python": "a=int(input())\nb=map(int,input().split())\nc={}\nfor i in b:\n\tif i in c:\n\t\tc[i]+=1 \n\telse:\n\t\tc[i]=1 \nfor i in sorted(c.items(),key=lambda x:x[0]): \n\tprint('{}:{}'.format(i[0],i[1]))\nnum=[]\nns=[]\nwhile True:\n\tn = input() \n\tif n == '':\n\t\tbreak\n\telse:\n\t\tnum .append(n.replace(';', ' ').replace(',', ' ').split())\n\t\tns.append(n)\ntry:\n\tfor a,b in zip(num,ns):\n\t\tresult=0\n\t\tfor i in a:\n\t\t\tresult += int(i)\n\t\tprint(b+f':{result}')\nexcept:\n\tprint('divided by zero')", + "topic_link": "https://bbs.csdn.net/topics/600470503", + "status": 0, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/28.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/29.json b/data_backup/python_code_json/29.json new file mode 100644 index 000000000..df8ba6d54 --- /dev/null +++ b/data_backup/python_code_json/29.json @@ -0,0 +1,18 @@ +{ + "question_id": 7447625, + "question_title": "根据指定值从一个列表中查找所有匹配元素的位置,要求使用列表中的index方法进行查找。", + "question_content": "

      题目内容:\n编写程序实现以下功能:根据指定值从一个列表中查找所有匹配元素的位置,要求使用列表中的index方法进行查找。\n \n输入格式:\n先输入待查找元素的值。\n再输入一个整数,表示列表中的元素个数。\n最后依次输入列表中的元素。\n \n输出格式:\n输出一个列表,各元素值为匹配元素的位置。如果没有匹配元素,则输出一个空列表。\n \n输入样例:\n10\n5\n5\n10\n15\n10\n20\n \n输出样例:\n[1, 3]\n \n输入样例:\n30\n5\n5\n10\n15\n10\n20\n \n输出样例:\n[]

      ", + "difficulty": "简单", + "answer_id": 53427546, + "answer_content": "
      \ncheck = input()\nnum = int(input())\nlist1 = []\nfor i in range(num):\n    x = input()\n    list1.append(x)\nindices = []\nstart = 0\nwhile 1:\n    try:\n        x = list1.index(check,start)\n        indices.append(x)\n        start = x+1\n    except:\n        break\nprint(indices)
      \n\n

      \"\"

      \n\n

       

      \n", + "tag_name": "python", + "python": "check = input()\nnum = int(input())\nlist1 = []\nfor i in range(num):\n\tx = input()\n\tlist1.append(x)\nindices = []\nstart = 0\nwhile 1:\n\ttry:\n\t\tx = list1.index(check,start)\n\t\tindices.append(x)\n\t\tstart = x+1\n\texcept:\n\t\tbreak\nprint(indices)", + "topic_link": "https://bbs.csdn.net/topics/600469987", + "status": 1, + "keywords": "散列表,散列表,算法中阶,数据结构", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/29.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/3.json b/data_backup/python_code_json/3.json new file mode 100644 index 000000000..79fb13f66 --- /dev/null +++ b/data_backup/python_code_json/3.json @@ -0,0 +1,17 @@ +{ + "question_id": 7431923, + "question_title": "运气最佳游戏", + "question_content": "

      运气最佳游戏:\n一群人排成一圈,按“1,2,......n”依次编号。然后从第1个人开始数,数到m把 踢出圈,其后的人再从1开始数,数到m,再把它踢出去......\n如此不停地进行下去直到最后只剩下一个人为止,那个人就是运气最佳。\n具体需求如下所示。\n编写函数模拟该游戏。\n根据用户输入的m和n,指定人的总数n和踢出第m个人。\n最后输出运气最佳的人的编号。

      ", + "difficulty": "简单", + "answer_id": 53400791, + "answer_content": "
      \nn = eval(input("请输入总人数:"))\nm = eval(input("请输踢出第几个人:"))\n\nlist1 = []\nfor i in range(1, n+1):\n    list1.append(i)\n\nwhile len(list1) != 1:\n    if len(list1) >= m:\n        list1 = list1[m:] + list1[0:m-1]\n        print(list1)\n    elif len(list1) < m:\n        while len(list1) != 1:\n            if m%len(list1) != 0:\n                list1 = list1[m%len(list1):] + list1[0:m%len(list1)-1]\n            else:\n                list1 = list1[0:-2]\n\nprint("最佳运气人编号为:%d号!"%list1[0])
      \n\n

      这个可以吗?

      \n", + "tag_name": "python", + "python": "n = eval(input(\"请输入总人数:\"))\nm = eval(input(\"请输踢出第几个人:\"))\nlist1 = []\nfor i in range(1, n+1):\n list1.append(i)\nwhile len(list1) != 1:\n if len(list1) >= m:\n list1 = list1[m:] + list1[0:m-1]\n print(list1)\n elif len(list1) < m:\n while len(list1) != 1:\n if m%len(list1) != 0:\n list1 = list1[m%len(list1):] + list1[0:m%len(list1)-1]\n else:\n list1 = list1[0:-2]\nprint(\"最佳运气人编号为:%d号!\"%list1[0])\n", + "topic_link": "https://bbs.csdn.net/topics/600470296", + "status": 0, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/3.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/30.json b/data_backup/python_code_json/30.json new file mode 100644 index 000000000..57fdf2ec7 --- /dev/null +++ b/data_backup/python_code_json/30.json @@ -0,0 +1,18 @@ +{ + "question_id": 7456701, + "question_title": "要求编写函数fn(a,n) 求a+aa+aaa++⋯+aa⋯aa(n个a)之和,fn须返回的是数列和", + "question_content": "

      要求编写函数fn(a,n) 求a+aa+aaa++⋯+aa⋯aa(n个a)之和,fn须返回的是数列和。\n从控制台输入正整数a和n的值(两个值都不超过9),并输出fn(a,n)的结果值。

      ", + "difficulty": "简单", + "answer_id": 53441357, + "answer_content": "
      \ndef fun(a,n):\n    s = 1\n    sum = 1\n    for i in range(1,n):\n        s = 1 + s*10\n        sum+=s\n    y = a *sum\n    print(y)\n\ndef main():\n    while(1):\n        a = int(input('请输入a:'))\n        if a>9 or a<0: \n            print('a的值输入错误,请重新输入:')\n        else:\n            break\n    while(1):\n        n = int(input('请输入n:'))\n        if n>9 or n<0: \n            print('n的值输入错误,请重新输入:')\n        else:\n            break\n    fun(a,n)\n \nif __name__ == '__main__':\n    main()\n
      \n\n

       

      \n", + "tag_name": "python", + "python": "def fun(a,n):\n\ts = 1\n\tsum = 1\n\tfor i in range(1,n):\n\t\ts = 1 + s*10\n\t\tsum+=s\n\ty = a *sum\n\tprint(y)\ndef main():\n\twhile(1):\n\t\ta = int(input('请输入a:'))\n\t\tif a>9 or a<0: \n\t\t\tprint('a的值输入错误,请重新输入:')\n\t\telse:\n\t\t\tbreak\n\twhile(1):\n\t\tn = int(input('请输入n:'))\n\t\tif n>9 or n<0: \n\t\t\tprint('n的值输入错误,请重新输入:')\n\t\telse:\n\t\t\tbreak\n\tfun(a,n)\nif __name__ == '__main__':\n\tmain()", + "topic_link": "https://bbs.csdn.net/topics/600469890", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/30.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/31.json b/data_backup/python_code_json/31.json new file mode 100644 index 000000000..e3dd91ffc --- /dev/null +++ b/data_backup/python_code_json/31.json @@ -0,0 +1,18 @@ +{ + "question_id": 7425433, + "question_title": "求两个给定正整数的最大公约数和最小公倍数", + "question_content": "

      本题要求两个给定正整数的最大公约数和最小公倍数。\n输入格式:\n输入在两行中分别输入正整数x和y。\n输出格式:\n在一行中输出最大公约数和最小公倍数的值。\n

      输入样例1:\n在这里给出一组输入。\n例如:

      100\n1520

      输出样例1:\n在这里给出相应的输出。\n例如:

      20 7600
      ", + "difficulty": "中等", + "answer_id": 53386909, + "answer_content": "
      \n"""该函数返回两个数的最大公约数""" \ndef hcf(x, y):\n   # 获取最小值\n   if x > y:\n       smaller = y\n   else:\n       smaller = x \n   for i in range(1,smaller + 1):\n       if((x % i == 0) and (y % i == 0)):\n           hcf = i \n   return hcf\n"""该函数返回两个数的最小公倍数""" \ndef lcm(x, y): \n   #  获取最大的数\n   if x > y:\n       greater = x\n   else:\n       greater = y\n \n   while(True):\n       if((greater % x == 0) and (greater % y == 0)):\n           lcm = greater\n           break\n       greater += 1\n \n   return lcm\n \n# 用户输入两个数字\nnum1 = int(input("输入第一个数字: "))\nnum2 = int(input("输入第二个数字: "))\n \nprint("最大公约数为",hcf(num1, num2),"最小公倍数为",lcm(num1,num2))
      \n\n

      运行结果:

      \n\n

      \"\"

      ", + "tag_name": "python", + "python": "def hcf(x, y):\n if x > y:\n\t smaller = y\n else:\n\t smaller = x \n for i in range(1,smaller + 1):\n\t if((x % i == 0) and (y % i == 0)):\n\t\t hcf = i \n return hcf\ndef lcm(x, y): \n if x > y:\n\t greater = x\n else:\n\t greater = y\n while(True):\n\t if((greater % x == 0) and (greater % y == 0)):\n\t\t lcm = greater\n\t\t break\n\t greater += 1\n return lcm\nnum1 = int(input(\"输入第一个数字: \"))\nnum2 = int(input(\"输入第二个数字: \"))\nprint(\"最大公约数为\",hcf(num1, num2),\"最小公倍数为\",lcm(num1,num2))", + "topic_link": "https://bbs.csdn.net/topics/600469988", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/31.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/32.json b/data_backup/python_code_json/32.json new file mode 100644 index 000000000..67b56187c --- /dev/null +++ b/data_backup/python_code_json/32.json @@ -0,0 +1,18 @@ +{ + "question_id": 759934, + "question_title": "将一个列表中字典字段相同的元素合并并且值相加", + "question_content": "如下两个列表,需要将oldList转化为newList,去掉相同字段的字典,并且去掉的参数里面的值要相加\noldList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1972},\n {'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},\n {'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1450},\n {'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},\n {'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1334}]\nnewList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 4756},\n {'3-3': 406, '3-2': 0, '3-1': 0, '3-0': 0}]\n", + "difficulty": "简单", + "answer_id": 816448, + "answer_content": "你好,我写了一种方式供你参考,希望可以帮到你。\n\n```\nimport operator\n\noldList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1972},\n {'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},\n {'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1450},\n {'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},\n {'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1334}]\n\nnewList = []\n\n# 先把oldList第一个元素给newList,防止下面for循环中newList为空\nnewList.append(oldList[0])\n\n# 每给newList添加一个元素时都和前面的比较,若keys()相同,则合并\nfor t in range(1,len(oldList)):\n for li in newList:\n if operator.eq(li.keys(), oldList[t].keys()):\n for key in li.keys():\n li[key] += oldList[t][key]\n break\n # 若keys()都不相同,则把新元素添加到newList\n elif operator.eq(li,newList[-1]):\n newList.append(oldList[t])\n break\n\nprint(newList)\n\n```", + "tag_name": "python", + "python": "import operator\noldList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1972},\n\t\t {'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},\n\t\t {'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1450},\n\t\t {'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},\n\t\t {'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1334}]\nnewList = []\nnewList.append(oldList[0])\nfor t in range(1,len(oldList)):\n\tfor li in newList:\n\t\tif operator.eq(li.keys(), oldList[t].keys()):\n\t\t\tfor key in li.keys():\n\t\t\t\tli[key] += oldList[t][key]\n\t\t\tbreak\n\t\telif operator.eq(li,newList[-1]):\n\t\t\tnewList.append(oldList[t])\n\t\t\tbreak\nprint(newList)", + "topic_link": "https://bbs.csdn.net/topics/600469989", + "status": 1, + "keywords": "散列表,散列表,算法中阶,数据结构", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/32.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/33.json b/data_backup/python_code_json/33.json new file mode 100644 index 000000000..c3de79cc7 --- /dev/null +++ b/data_backup/python_code_json/33.json @@ -0,0 +1,18 @@ +{ + "question_id": 7443246, + "question_title": "字符串统计", + "question_content": "

      从键盘输入一个包含有英文字母、数字、空格和其它字符的字符串,并分别实现下面的功能:统计字符串中出现2次的英文字母(区分大小写)\n统计字符串中出现n次的数字,n从键盘输入

      ", + "difficulty": "简单", + "answer_id": 53420309, + "answer_content": "
      \n#第一题\ns=input('input a string:\\n')\ndict1={}\nfor c in s:\n    if c.isalpha():\n        if w not in dict1.keys():\n            dict1[w] = 1\n        else:\n            dict1[w] += 1\nfor key in dict1.keys():\n    if dict1[key]==2:\n        print(key)\n\n\n\n#第二题\ns=input('input a string:\\n')\nn=int(input('input a n:\\n'))\ndict2={}\nfor c in s:\n    if c.isdigit():\n        if m not in dict2.keys():\n            dict2[m] = 1\n        else:\n            dict2[m] += 1\nfor key in dict2.keys():\n    if dict2[key]==n:\n        print(key)\n
      \n\n

       

      \n", + "tag_name": "python", + "python": "#第一题\ns=input('input a string:\\n')\ndict1={}\nfor c in s:\n\tif c.isalpha():\n\t\tif c not in dict1.keys():\n\t\t\tdict1[c] = 1\n\t\telse:\n\t\t\tdict1[c] += 1\nfor key in dict1.keys():\n\tif dict1[key]==2:\n\t\tprint(key)\n#第二题\ns=input('input a string:\\n')\nn=int(input('input a n:\\n'))\ndict2={}\nfor c in s:\n\tif c.isdigit():\n\t\tif c not in dict2.keys():\n\t\t\tdict2[c] = 1\n\t\telse:\n\t\t\tdict2[c] += 1\nfor key in dict2.keys():\n\tif dict2[key]==n:\n\t\tprint(key)", + "topic_link": "https://bbs.csdn.net/topics/600470406", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/33.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/34.json b/data_backup/python_code_json/34.json new file mode 100644 index 000000000..1260a3d43 --- /dev/null +++ b/data_backup/python_code_json/34.json @@ -0,0 +1,17 @@ +{ + "question_id": 1098045, + "question_title": "knn算法", + "question_content": "k近邻法 的算法\n编写一个代码(其输入参数包含下面内容)\n输入2个类别的数据(都是二维的坐标点),可设输入每一类约10个点\n输入一个坐标点的坐标\n输出:使用K近邻法判断该坐标点属于哪个类别", + "difficulty": "中等", + "answer_id": 1312397, + "answer_content": "```python\n#!/usr/bin/python\n# coding=utf-8\n#########################################\n# kNN: k Nearest Neighbors\n\n# 输入: newInput: (1xN)的待分类向量\n# dataSet: (NxM)的训练数据集\n# labels: 训练数据集的类别标签向量\n# k: 近邻数\n\n# 输出: 可能性最大的分类标签\n#########################################\n\nfrom numpy import *\nimport operator\n\n# 创建一个数据集,包含2个类别共4个样本\ndef createDataSet():\n # 生成一个矩阵,每行表示一个样本\n group = array([[1.0, 0.9], [1.0, 1.0], [0.1, 0.2], [0.0, 0.1]])\n # 4个样本分别所属的类别\n labels = ['A', 'A', 'B', 'B']\n return group, labels\n\n# KNN分类算法函数定义\ndef kNNClassify(newInput, dataSet, labels, k):\n numSamples = dataSet.shape[0] # shape[0]表示行数\n\n # # step 1: 计算距离[\n # 假如:\n # Newinput:[1,0,2]\n # Dataset:\n # [1,0,1]\n # [2,1,3]\n # [1,0,2]\n # 计算过程即为:\n # 1、求差\n # [1,0,1] [1,0,2]\n # [2,1,3] -- [1,0,2]\n # [1,0,2] [1,0,2]\n # =\n # [0,0,-1]\n # [1,1,1]\n # [0,0,-1]\n # 2、对差值平方\n # [0,0,1]\n # [1,1,1]\n # [0,0,1]\n # 3、将平方后的差值累加\n # [1]\n # [3]\n # [1]\n # 4、将上一步骤的值求开方,即得距离\n # [1]\n # [1.73]\n # [1]\n #\n # ]\n # tile(A, reps): 构造一个矩阵,通过A重复reps次得到\n # the following copy numSamples rows for dataSet\n diff = tile(newInput, (numSamples, 1)) - dataSet # 按元素求差值\n squaredDiff = diff ** 2 # 将差值平方\n squaredDist = sum(squaredDiff, axis = 1) # 按行累加\n distance = squaredDist ** 0.5 # 将差值平方和求开方,即得距离\n\n # # step 2: 对距离排序\n # argsort() 返回排序后的索引值\n sortedDistIndices = argsort(distance)\n classCount = {} # define a dictionary (can be append element)\n for i in xrange(k):\n # # step 3: 选择k个最近邻\n voteLabel = labels[sortedDistIndices[i]]\n\n # # step 4: 计算k个最近邻中各类别出现的次数\n # when the key voteLabel is not in dictionary classCount, get()\n # will return 0\n classCount[voteLabel] = classCount.get(voteLabel, 0) + 1\n\n # # step 5: 返回出现次数最多的类别标签\n maxCount = 0\n for key, value in classCount.items():\n if value > maxCount:\n maxCount = value\n maxIndex = key\n\n return maxIndex\n```\n```python\n#!/usr/bin/python\n# coding=utf-8\nimport KNN\nfrom numpy import *\n# 生成数据集和类别标签\ndataSet, labels = KNN.createDataSet()\n# 定义一个未知类别的数据\ntestX = array([1.2, 1.0])\nk = 3\n# 调用分类函数对未知数据分类\noutputLabel = KNN.kNNClassify(testX, dataSet, labels, 3)\nprint \"Your input is:\", testX, \"and classified to class: \", outputLabel\n\ntestX = array([0.1, 0.3])\noutputLabel = KNN.kNNClassify(testX, dataSet, labels, 3)\nprint \"Your input is:\", testX, \"and classified to class: \", outputLabel\n```", + "tag_name": "python", + "python": "from numpy import *\nimport operator\ndef createDataSet():\n\tgroup = array([[1.0, 0.9], [1.0, 1.0], [0.1, 0.2], [0.0, 0.1]])\n\tlabels = ['A', 'A', 'B', 'B']\n\treturn group, labels\ndef kNNClassify(newInput, dataSet, labels, k):\n\tnumSamples = dataSet.shape[0] \n\tdiff = tile(newInput, (numSamples, 1)) - dataSet \n\tsquaredDiff = diff ** 2 \n\tsquaredDist = sum(squaredDiff, axis = 1) \n\tdistance = squaredDist ** 0.5 \n\tsortedDistIndices = argsort(distance)\n\tclassCount = {} \n\tfor i in range(k):\n\t\tvoteLabel = labels[sortedDistIndices[i]]\n\t\tclassCount[voteLabel] = classCount.get(voteLabel, 0) + 1\n\tmaxCount = 0\n\tfor key, value in classCount.items():\n\t\tif value > maxCount:\n\t\t\tmaxCount = value\n\t\t\tmaxIndex = key\n\treturn maxIndex", + "topic_link": "https://bbs.csdn.net/topics/600470407", + "status": 0, + "keywords": "分治法,算法初阶,基础知识,算法基础,设计算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/34.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/35.json b/data_backup/python_code_json/35.json new file mode 100644 index 000000000..7aea6ddfa --- /dev/null +++ b/data_backup/python_code_json/35.json @@ -0,0 +1,18 @@ +{ + "question_id": 7418328, + "question_title": "求列表(整数列表)的平衡点", + "question_content": "对于一个整数列表,如果有一个切分位置使其前面的元素之和等于后面的元素之和,就称该位置是平衡点\n请编写程序求列表(整数列表)的平衡点,不存在时给出提示。\n思路:\n1.确定一个位置\n2.求在这个位置前面的元素之和,与在这个位置后面的元素之和,做比较,判断是否相等\n 2.1 怎么求前面元素之和:\n 假设这个位置是[i],那么前面元素就是[0]~[i-1], 后面元素为[i+1]~[len(list)-1]\n 进行求和:累加求和\n 2.2判断是否相等:相等,给出这个平衡位置;不相等,输出“该列表不存在平衡点”", + "difficulty": "中等", + "answer_id": 53374253, + "answer_content": "
      \na=input('请输入一个整数列表:').split(",")\nflag=0\nfor i in range(0,len(a)-1):\n    s1=0\n    for m in range(0,i):\n        s1+=int(a[m])\n    s2=0\n    for n in range(i+1,len(a)):\n        s2+=int(a[n])\n    if s1==s2:\n        print('该整数列表存在平衡点,且平衡点为:',a[i])\n        flag=1\n        break\nif flag==0:\n    print('该整数列表不存在平衡点')6
      \n\n

       

      ", + "tag_name": "python", + "python": "a=input('请输入一个整数列表:').split(\",\")\nflag=0\nfor i in range(0,len(a)-1):\n\ts1=0\n\tfor m in range(0,i):\n\t\ts1+=int(a[m])\n\ts2=0\n\tfor n in range(i+1,len(a)):\n\t\ts2+=int(a[n])\n\tif s1==s2:\n\t\tprint('该整数列表存在平衡点,且平衡点为:',a[i])\n\t\tflag=1\n\t\tbreak\nif flag==0:\n\tprint('该整数列表不存在平衡点')", + "topic_link": "https://bbs.csdn.net/topics/600470504", + "status": 1, + "keywords": "散列表,散列表,算法中阶,数据结构", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/35.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/36.json b/data_backup/python_code_json/36.json new file mode 100644 index 000000000..7e55f3802 --- /dev/null +++ b/data_backup/python_code_json/36.json @@ -0,0 +1,18 @@ +{ + "question_id": 7436880, + "question_title": "计算出因子里面4和7的个数", + "question_content": "

      输入一个正数n,计算出因子里面分别有几个4和7,输出因子中4和7的个位数

      ", + "difficulty": "简单", + "answer_id": 53409217, + "answer_content": "
      \nn = int(input("输入数字:"))\nfactor = [n]   # 包括n?\nnum = 1\nwhile num <= n/2+1:\n    if n % num == 0:\n        factor.append(num)\n    num = num + 1\nprint(factor)\nm = [str(i) for i in factor]\ncount4 = 0\ncount7 = 0\nfor i in m:\n    if '4' in i:\n        count4 += 1\n        print('以4结尾的因子的个位数:', int(i)%10)\n    if '7' in i:\n        count7 += 1\n        print('以7结尾的因子的个位数:', int(i)%10)\nprint('因子里面分别有{0}个4和{1}个7'.format(count4,count7))
      \n\n

      这里的因子包括了数字本身,如果不想包括可以将factor 初始化为[]

      \n\n

      输入:140

      \n\n

      输出:

      \n\n
      \n[140, 1, 2, 4, 5, 7, 10, 14, 20, 28, 35, 70]\n以4结尾的因子的个位数: 0\n以4结尾的因子的个位数: 4\n以7结尾的因子的个位数: 7\n以4结尾的因子的个位数: 4\n以7结尾的因子的个位数: 0\n因子里面分别有3个4和2个7
      \n\n

       

      \n", + "tag_name": "python", + "python": "n = int(input(\"输入数字:\"))\nfactor = [n] \nnum = 1\nwhile num <= n/2+1:\n\tif n % num == 0:\n\t\tfactor.append(num)\n\tnum = num + 1\nprint(factor)\nm = [str(i) for i in factor]\ncount4 = 0\ncount7 = 0\nfor i in m:\n\tif '4' in i:\n\t\tcount4 += 1\n\t\tprint('以4结尾的因子的个位数:', int(i)%10)\n\tif '7' in i:\n\t\tcount7 += 1\n\t\tprint('以7结尾的因子的个位数:', int(i)%10)\nprint('因子里面分别有{0}个4和{1}个7'.format(count4,count7))", + "topic_link": "https://bbs.csdn.net/topics/600470505", + "status": 1, + "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/36.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/37.json b/data_backup/python_code_json/37.json new file mode 100644 index 000000000..02f40aa90 --- /dev/null +++ b/data_backup/python_code_json/37.json @@ -0,0 +1,18 @@ +{ + "question_id": 7433771, + "question_title": "检查密码强度", + "question_content": "

      定义一个名为“isStrongPassword”的函数,该函数将字符串作为参数。功能然后将检查所提供的字符串是否满足以下条件,以检查是否为强 \n密码:\n1.必须至少包含1个大写和小写字母的组合\n2.必须至少包含3位数字\n3.必须至少包含3个特殊字符(包括空格)\n4.密码长度必须至少12个字符\n该函数将返回一个布尔值,即如果满足所有条件则返回True或返回False\n确保使用可能返回False值的每个可能的输入来测试函数也一样

      ", + "difficulty": "简单", + "answer_id": 53404077, + "answer_content": "
      \n\ndef isStrongPassword(pwd):\n    chars = list(pwd)\n    upper = [c for c in chars if 'A' <= c and c <= 'Z']\n    lower = [c for c in chars if 'a' <= c and c <= 'z']\n    digit = [c for c in chars if '0' <= c and c <= '9' ]\n    symbol = [c for c in chars if not ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z' or '0' <= c and c <= '9')] \n    strong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12\n    return strong\n    \n    \n    \nprint(isStrongPassword("Str0n9P@$$w0rd"))\nprint(isStrongPassword("StrongPassword"))\nprint(isStrongPassword("Stron9P@$$0rd"))\nprint(isStrongPassword("Str0n9Pass0rd"))\nprint(isStrongPassword("str0n9p@$$0rd"))\nprint(isStrongPassword("Str0n9P@$$"))\nprint(isStrongPassword("12345678"))\nprint(isStrongPassword("~!@#$%^&*()_+"))\nprint(isStrongPassword("STRONGPASSWORD"))\n\n\n# output\nTrue\nFalse\nFalse\nFalse\nFalse\nFalse\nFalse\nFalse\nFalse
      \n\n

       

      \n", + "tag_name": "python", + "python": "def isStrongPassword(pwd):\n\tchars = list(pwd)\n\tupper = [c for c in chars if 'A' <= c and c <= 'Z']\n\tlower = [c for c in chars if 'a' <= c and c <= 'z']\n\tdigit = [c for c in chars if '0' <= c and c <= '9' ]\n\tsymbol = [c for c in chars if not ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z' or '0' <= c and c <= '9')] \n\tstrong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12\n\treturn strong\nprint(isStrongPassword(\"Str0n9P@$$w0rd\"))\nprint(isStrongPassword(\"StrongPassword\"))\nprint(isStrongPassword(\"Stron9P@$$0rd\"))\nprint(isStrongPassword(\"Str0n9Pass0rd\"))\nprint(isStrongPassword(\"str0n9p@$$0rd\"))\nprint(isStrongPassword(\"Str0n9P@$$\"))\nprint(isStrongPassword(\"12345678\"))\nprint(isStrongPassword(\"~!@#$%^&*()_+\"))\nprint(isStrongPassword(\"STRONGPASSWORD\"))", + "topic_link": "https://bbs.csdn.net/topics/600469891", + "status": 1, + "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/37.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/38.json b/data_backup/python_code_json/38.json new file mode 100644 index 000000000..975c5bd2c --- /dev/null +++ b/data_backup/python_code_json/38.json @@ -0,0 +1,17 @@ +{ + "question_id": 7450710, + "question_title": "Python 文件 分数统计", + "question_content": "

      【问题描述】

      \n\n

       

      \n\n

      从一个文本文件内读入任意多个学生的分数,求出最高分,最低分和平均分存入文件result.txt内。

      \n\n

       

      \n\n

      【输入形式】

      \n\n

       

      \n\n

      一个文件,文件中分数之间由换行隔开,输入的文件名为grade.txt。输入的分数都是整数。

      \n\n

       

      \n\n

      【输出形式】

      \n\n

       

      \n\n

      计算出grade.txt中所有分数的最高分,最低分和平均分并分3行存入result.txt的文件内。平均分保留1位小数。

      \n\n

       

      \n\n

      【样例输入】

      \n\n

       

      \n\n

      60

      \n\n

       

      \n\n

      70

      \n\n

       

      \n\n

      80

      \n\n

       

      \n\n

      【样例输出】

      \n\n

       

      \n\n

      80

      \n\n

       

      \n\n

      60

      \n\n

       

      \n\n

      70

      \n\n

       

      ", + "difficulty": "简单", + "answer_id": 53431675, + "answer_content": "
      \ngrade = input()\nwhile grade != "":\n    with open("../Down/Setting/zgtest.txt",'a') as f:\n        f.write(grade + '\\n')\n    grade = input()\nwith open("grade.txt",'r') as f: #读出分数到列表\n    keys = list(set(f.readlines()))\nindex = 0\nwhile(index < len(keys)): #处理读出来的分数为整数\n    keys[index] = int(keys[index].replace('\\n',''))\n    index = index + 1\nwith open("result.txt",'a') as r: #写入结果\n    r.write(str(max(keys)) + '\\n')\n    r.write(str(min(keys)) + '\\n')\n    avg = round(sum(keys) / len(keys),1)\n    r.write(str(avg) + '\\n')\n
      \n\n

       

      \n", + "tag_name": "python", + "python": "grade = input()\nwhile grade != \"\":\n\twith open(\"../Down/Setting/zgtest.txt\",'a') as f:\n\t\tf.write(grade + '\\n')\n\tgrade = input()\nwith open(\"grade.txt\",'r') as f: \n\tkeys = list(set(f.readlines()))\nindex = 0\nwhile(index < len(keys)): \n\tkeys[index] = int(keys[index].replace('\\n',''))\n\tindex = index + 1\nwith open(\"result.txt\",'a') as r: \n\tr.write(str(max(keys)) + '\\n')\n\tr.write(str(min(keys)) + '\\n')\n\tavg = round(sum(keys) / len(keys),1)\n\tr.write(str(avg) + '\\n')", + "topic_link": "https://bbs.csdn.net/topics/600470408", + "status": 0, + "keywords": "算法高阶,计算几何学,算法问题选编,确定任意一对线段是否相交", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/38.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/39.json b/data_backup/python_code_json/39.json new file mode 100644 index 000000000..a20a47a5c --- /dev/null +++ b/data_backup/python_code_json/39.json @@ -0,0 +1,18 @@ +{ + "question_id": 6750637, + "question_title": "Python编程 随机生成一个具有 20 个元素的元素值在 1-10 之间的列表", + "question_content": "

      随机生成一个具有 20 个元素的元素值在 1-10 之间的列表,输出连续最长数的个数。

      ", + "difficulty": "简单", + "answer_id": 51592169, + "answer_content": "
      \nimport random\na = [random.randint(1,10) for i in range(20)]\nprint(a)\nl = rl = 1\nn = rn = a[0]\nfor v in a[1:]:\n    if v==n:\n        l += 1\n        if l>rl:\n            rl = l\n            rn = v\n    else:\n        l = 1\n        n = v\nprint(f'连续最长的数是{rn},连续了{rl}次')\n
      \n\n

       

      ", + "tag_name": "python", + "python": "import random\na = [random.randint(1,10) for i in range(20)]\nprint(a)\nl = rl = 1\nn = rn = a[0]\nfor v in a[1:]:\n\tif v==n:\n\t\tl += 1\n\t\tif l>rl:\n\t\t\trl = l\n\t\t\trn = v\n\telse:\n\t\tl = 1\n\t\tn = v\nprint(f'连续最长的数是{rn},连续了{rl}次')", + "topic_link": "https://bbs.csdn.net/topics/600469892", + "status": 1, + "keywords": "散列表,散列表,算法中阶,数据结构", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/39.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/4.json b/data_backup/python_code_json/4.json new file mode 100644 index 000000000..994bdbd6b --- /dev/null +++ b/data_backup/python_code_json/4.json @@ -0,0 +1,18 @@ +{ + "question_id": 7411744, + "question_title": "编写Python程序实现素数处理的功能", + "question_content": "

      编写Python程序实现素数处理的功能,要求如下:

      (1)从键盘输入一个整数X,编写一个函数Find(x=100),找出1—X之间的所有的素数(即质数),并将这些素数按照升序存放在列表 prime_list []中。

      (2)在程序中编写一个函数delete_seven( prime_list),将 prime_list []中个位含有7的素数删除;

      【程序要求:】

      (1)有引导用户键盘输入的提示信息,言语要恰当;

      (2)函数Find(x=100)实现要正确,实现列表 prime_list []中查询到的素数的输出;

      (3)函数delete_seven( prime_list)实现正确,输出删除指定素数后的相关数据信息。

      ", + "difficulty": "简单", + "answer_id": 53363059, + "answer_content": "
      \ndef find(x=100):\n    pl = []\n    for m in range(2,x+1):\n        for k in pl:\n            if m % k == 0:\n                break\n        else:\n            pl.append(m)\n    return pl\n\ndef delete_seven(pl):\n    return [x for x in pl if x%10!=7]\n\nx = int(input('输入一个整数:'))\nprime_list = find(x)\nprint(prime_list)\nprint(delete_seven(prime_list))\n\n
      \n\n

      \"\"

      ", + "tag_name": "python", + "python": "def find(x=100):\n\tpl = []\n\tfor m in range(2,x+1):\n\t\tfor k in pl:\n\t\t\tif m % k == 0:\n\t\t\t\tbreak\n\t\telse:\n\t\t\tpl.append(m)\n\treturn pl\ndef delete_seven(pl):\n\treturn [x for x in pl if x%10!=7]\nx = int(input('输入一个整数:'))\nprime_list = find(x)\nprint(prime_list)\nprint(delete_seven(prime_list))", + "topic_link": "https://bbs.csdn.net/topics/600470199", + "status": 1, + "keywords": "散列表,算法中阶,数据结构,散列函数", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/4.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/40.json b/data_backup/python_code_json/40.json new file mode 100644 index 000000000..2d9f30413 --- /dev/null +++ b/data_backup/python_code_json/40.json @@ -0,0 +1,18 @@ +{ + "question_id": 864358, + "question_title": "请问如何用python做两个数组逐位判断?", + "question_content": "比如有以下数组:\na1: 1,0,0,1,0,0,0,1\na2: 0,0,0,0,1,1,1,1\na3: 0,1,0,1,0,1,0,0\na4: 1,0,1,1,1,1,0,0\na5: .......\n抓取三个数组进行判断,\n if ((a1第一位or a2第一位 or a3第一位=1 )and (a1第二位 or a2 第二位 or a3第二位=1)and....\n直到判断完所有位数为止,所有位都有了1的话就输出当前这三个数组,已输出的数组不参与之后的判断。", + "difficulty": "简单", + "answer_id": 993346, + "answer_content": "不知道抓取3个数组是任意3个,比如123 124 125 134 135 235...,还是顺序联系的3个,123 456 789这样抓。\n我是按照前者写的,如果不是,请说明\n```\n# -*- coding: UTF-8 -*-\nfrom itertools import combinations\n\na1=[ 1,0,0,1,0,0,0,1]\na2=[ 0,0,0,0,1,1,1,1]\na3=[ 0,1,0,1,0,1,0,0]\na4=[ 1,0,1,1,1,1,0,0]\na5=[ 1,1,1,1,1,1,1,0]\na6=[ 0,0,0,0,0,0,0,1]\na=[a1,a2,a3,a4,a5,a6]\n\nal = list(combinations(a,3))\nfor i in al:\n flag = True\n for j in range(len(i[0])):\n if (i[0][j] + i[1][j] + i[2][j] == 0):\n flag = False\n break\n if flag:\n print(i) \n\t\t\n```\n([1, 0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 0])\n([1, 0, 0, 1, 0, 0, 0, 1], [0, 1, 0, 1, 0, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0])\n([1, 0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0])\n([1, 0, 0, 1, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1])\n([0, 0, 0, 0, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 0], [1, 0, 1, 1, 1, 1, 0, 0])\n([0, 0, 0, 0, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0])\n([0, 0, 0, 0, 1, 1, 1, 1], [1, 0, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0])\n([0, 0, 0, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1])\n([0, 1, 0, 1, 0, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1])\n([1, 0, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1])\n\n----------------------------\n只使用1次\n\n```\n# -*- coding: UTF-8 -*-\nfrom itertools import combinations\n\na1=[ 1,0,0,1,0,0,0,1]\na2=[ 0,0,0,0,1,1,1,1]\na3=[ 0,1,0,1,0,1,0,0]\na4=[ 1,0,1,1,1,1,0,0]\na5=[ 1,1,1,1,1,1,1,0]\na6=[ 0,0,0,0,0,0,0,1]\na=[a1,a2,a3,a4,a5,a6]\nal = list(combinations(list(i for i in range(0, 6)),3))\nused = []\nfor i in al:\n\tflag = False\n\tif not(i[0] in used or i[1] in used or i[2] in used):\n\t\tflag = True\n\t\tfor j in range(7):\n\t\t\tif (a[i[0]][j] + a[i[1]][j] + a[i[2]][j] == 0):\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\tif flag:\n\t\tused.append(i[0])\n\t\tused.append(i[1])\n\t\tused.append(i[2])\n\t\tprint(' '.join(map(str, a[i[0]])) + \"; \" + ' '.join(map(str, a[i[1]])) + \"; \" + ' '.join(map(str, a[i[2]])))\n\t\t\n```\n1 0 0 1 0 0 0 1; 0 0 0 0 1 1 1 1; 1 1 1 1 1 1 1 0\n", + "tag_name": "python", + "python": "# -*- coding: UTF-8 -*-\nfrom itertools import combinations\na1=[ 1,0,0,1,0,0,0,1]\na2=[ 0,0,0,0,1,1,1,1]\na3=[ 0,1,0,1,0,1,0,0]\na4=[ 1,0,1,1,1,1,0,0]\na5=[ 1,1,1,1,1,1,1,0]\na6=[ 0,0,0,0,0,0,0,1]\na=[a1,a2,a3,a4,a5,a6]\nal = list(combinations(a,3))\nfor i in al:\n\tflag = True\n\tfor j in range(len(i[0])):\n\t\tif (i[0][j] + i[1][j] + i[2][j] == 0):\n\t\t\tflag = False\n\t\t\tbreak\n\tif flag:\n\t\tprint(i)\t", + "topic_link": "https://bbs.csdn.net/topics/600469990", + "status": 1, + "keywords": "算法初阶,基础知识,分治策略,最大子数组问题", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/40.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/41.json b/data_backup/python_code_json/41.json new file mode 100644 index 000000000..86213fe9a --- /dev/null +++ b/data_backup/python_code_json/41.json @@ -0,0 +1,18 @@ +{ + "question_id": 7427183, + "question_title": "python 编写函数计算圆周率", + "question_content": "

      计算圆周率。存在圆心在直角坐标系原点且半径为 1 的圆及其外切正方形。为计算方便,仅考虑位于第一象限的四分之一正方形和四分之一圆。随机生成该四分之一正方形中一系列点,散布于四分之一圆内比例即为圆周率四分之一。散步点越多,结果越精确,耗时也越长。

      ", + "difficulty": "简单", + "answer_id": 53391236, + "answer_content": "
      \nfrom random import random\nfrom math import sqrt\n\nN=eval(input("请输入次数:"))\n#散在园内部点为0\nK=0 \n#循环撒点的过程看成是遍历循环的过程,用for in range对所有点进行抛洒\nfor i in range(1,N+1):\n#    定义x,y当作两个随机数的坐标值,这个坐标就是圆的抛点\n    x,y=random(),random()\n#    如何判断这个坐标就在圆内呢?判断这个点到圆心的距离是否等于1\n    dist =sqrt(x**2+y**2)\n    if dist<=1.0:\n        K=K+1\n#用这个值比上整个区域值\npi=4*(K/N)    \nprint("圆周率值:{}".format(pi))
      \n\n

      运行结果

      \n\n
      \n请输入次数:666666\n圆周率值:3.1404271404271404
      \n\n

       

      ", + "tag_name": "python", + "python": "from random import random\nfrom math import sqrt\nN=eval(input(\"请输入次数:\"))\nK=0 \nfor i in range(1,N+1):\n\tx,y=random(),random()\n\tdist =sqrt(x**2+y**2)\n\tif dist<=1.0:\n\t\tK=K+1\npi=4*(K/N)\t\nprint(\"圆周率值:{}\".format(pi))", + "topic_link": "https://bbs.csdn.net/topics/600469893", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/41.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/42.json b/data_backup/python_code_json/42.json new file mode 100644 index 000000000..e396466d5 --- /dev/null +++ b/data_backup/python_code_json/42.json @@ -0,0 +1,17 @@ +{ + "question_id": 7456509, + "question_title": "随机分组", + "question_content": "用python实现随机分组 要求3~4人一组", + "difficulty": "简单", + "answer_id": 53440302, + "answer_content": "
      \nimport random\n \n \n# 构建分身数据源(25个分身对象)\ndef get_source_data():\n    data = []\n    for i in range(4):\n        data.append({"name":"组长", "role":i}) # role表示分身ID\n    for i in range(7):\n        for j in range(3):\n            data.append({"name": "组员" + str(i), "role": j})\n    return data\n \n \n# 进行5次选择,选出5组\ndef group_by_random():\n    des_list = []\n    data_list = get_source_data()\n    for i in range(5): # 分5组\n        one_list = []\n        has_selected = {} # 标记某个人是否已经被添加进当前组中\n        while(len(one_list) < 5): # 直到每组中有5个不同的人(组中最多有同一个人的1个分身)\n            index = random.randint(0, len(data_list)-1)\n            person = data_list[index]\n            # 如果这个人(此处不区分“分身”,只区分“人”)没有被添加到当前组中,就添加该分身到组中,同时删除原数据列表中的这个分身对象\n            if not has_selected.__contains__(person["name"]): \n                one_list.append(person["name"])\n                data_list.pop(index)\n                has_selected[person["name"]] = True\n        des_list.append(one_list)\n    return des_list\n \n \nif __name__ == '__main__':\n    for group in group_by_random():\n        print("分组:", group)
      \n\n

      \"\"

      \n\n

      如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢
      \n 

      \n", + "tag_name": "python", + "python": "import random\ndef get_source_data():\n\tdata = []\n\tfor i in range(4):\n\t\tdata.append({\"name\":\"组长\", \"role\":i}) \n\tfor i in range(7):\n\t\tfor j in range(3):\n\t\t\tdata.append({\"name\": \"组员\" + str(i), \"role\": j})\n\treturn data\ndef group_by_random():\n\tdes_list = []\n\tdata_list = get_source_data()\n\tfor i in range(5): \n\t\tone_list = []\n\t\thas_selected = {} \n\t\twhile(len(one_list) < 5): \n\t\t\tindex = random.randint(0, len(data_list)-1)\n\t\t\tperson = data_list[index]", + "topic_link": "https://bbs.csdn.net/topics/600470409", + "status": 0, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/42.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/43.json b/data_backup/python_code_json/43.json new file mode 100644 index 000000000..81e569cfa --- /dev/null +++ b/data_backup/python_code_json/43.json @@ -0,0 +1,18 @@ +{ + "question_id": 7456124, + "question_title": "新浪微博热门话题", + "question_content": "

      新浪微博可以在发言中嵌入“话题”,即将发言中的话题文字写在一对“#”之间,就可以生成话题链接,点击链接可以看到有多少人在跟自己讨论相同或者相似的话题。新浪微博还会随时更新热门话题列表,并将最热门的话题放在醒目的位置推荐大家关注。\n \n本题目要求实现一个简化的热门话题推荐功能,从大量英文(因为中文分词处理比较麻烦)微博中解析出话题,找出被最多条微博提到的话题。\n \n输入格式:\n输入说明:输入首先给出一个正整数N(≤10​5​​),随后N行,每行给出一条英文微博,其长度不超过140个字符。任何包含在一对最近的#中的内容均被认为是一个话题,输入保证#成对出现。\n输出格式:\n第一行输出被最多条微博提到的话题,第二行输出其被提到的微博条数。如果这样的话题不唯一,则输出按字母序最小的话题,并在第三行输出And k more ...,其中k是另外几条热门话题的条数。输入保证至少存在一条话题。\n注意:两条话题被认为是相同的,如果在去掉所有非英文字母和数字的符号、并忽略大小写区别后,它们是相同的字符串;同时它们有完全相同的分词。输出时除首字母大写外,只保留小写英文字母和数字,并用一个空格分隔原文中的单词。\n输入样例:\n4\nThis is a #test of topic#.\nAnother #Test of topic.#\nThis is a #Hot# #Hot# topic\nAnother #hot!# #Hot# topic\n输出样例:\nHot\n2\nAnd 1 more

      ", + "difficulty": "简单", + "answer_id": 53439642, + "answer_content": "
      \nimport re\n\na = int(input('输入微博数量(小于等于105的正整数):'))\nb = []\nc = []\nwhile len(b)<a:\n    x = input('请输入微博内容,小于140字:')\n    if len(x)<140:\n        b.append(x)\n    else:\n        print('信息超出140字限制,请从新输入。')\n    c += re.findall('#[^#]+#',x)\nd = [{'n':n,'c':len(c)-len(re.findall('#[^#]+#',re.sub(n,'',''.join(c.copy()))))} for n in set(c)]\ne = sorted(d,key=lambda x:x['c'],reverse=True)\nprint(e[0]['n'].title())\nprint(e[0]['c'])
      \n\n

      做了个大概,同一微博之中,话题重复的我没有排重,排重需要去掉所有非英文字母和数字的符号、并忽略大小写区别,你自己实现以下,在c+=那一行,自己追加,排序没有实现同样数量的按字母再次排序,也自己去实现一下

      \n", + "tag_name": "python", + "python": "import re\na = int(input('输入微博数量(小于等于105的正整数):'))\nb = []\nc = []\nwhile len(b)(2)编写程序,完成以下功能:( a )设计一个空字典,用于存放用户的通信录(包括姓名和电话号码)。( b )程序运行后,显示用户选项:1新増联系人2查询联系人3删除联系人4退出程序( c )根据用户的选择,进入下一步,执行相应的功能,完成通信录的增加、查询、删除以及退出系统的功能。

      ", + "difficulty": "简单", + "answer_id": 53395410, + "answer_content": "
      \nd = {}\nwhile 1:\n    s = input("显示用户选项:1新増联系人2查询联系人3删除联系人4退出程序")\n    if s == '1':\n        name = input("输入新增姓名:")\n        number = input("输入电话号码:")\n        d[name] = number\n    if s == '2':\n        name = input("输入查询姓名:")\n        print(f'查询结果:{d.get(name, "")}')\n    if s == '3':\n        name = input("输入删除的姓名:")\n        del d[name]\n    if s == '4':\n        break
      \n\n

       

      \n", + "tag_name": "python", + "python": "d = {}\nwhile 1:\n\ts = input(\"显示用户选项:1新増联系人2查询联系人3删除联系人4退出程序\")\n\tif s == '1':\n\t\tname = input(\"输入新增姓名:\")\n\t\tnumber = input(\"输入电话号码:\")\n\t\td[name] = number\n\tif s == '2':\n\t\tname = input(\"输入查询姓名:\")\n\t\tprint(f'查询结果:{d.get(name, \"\")}')\n\tif s == '3':\n\t\tname = input(\"输入删除的姓名:\")\n\t\tdel d[name]\n\tif s == '4':\n\t\tbreak", + "topic_link": "https://bbs.csdn.net/topics/600469991", + "status": 0, + "keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/44.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/45.json b/data_backup/python_code_json/45.json new file mode 100644 index 000000000..18bea2e03 --- /dev/null +++ b/data_backup/python_code_json/45.json @@ -0,0 +1,18 @@ +{ + "question_id": 827445, + "question_title": "循环随机取数组直到得出指定数字?", + "question_content": "举个例子:\n随机数字范围:0~100\n每组数字量:6(s1,s2,s3,s4,s5,s6)\n第二轮开始随机数字范围:新s1和新s2取值为旧s1和s2之间,新s3和新s4取值为旧s3和s4之间,新s5和新s6取值为旧s5和s6之间。\n跳出循环条件:任意数字=37\n如因s1=s2!=37&&s3=s4!=37&&s5=s6!=37使数组进入无意义无限循环,则重新取0~100六个数字并开始如上述第二轮随机的随机取值。", + "difficulty": "简单", + "answer_id": 924449, + "answer_content": "\n```python\n#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport random\n\ndef random_test():\n # 初始化一个列表,随机0-100的6个数字\n rst_list = [random.randint(0,100) for i in range(0, 6)]\n print(rst_list)\n while 1:\n # 新建临时数据,用来存储rst_list按规则处理后的数据\n temp = []\n for k,v in enumerate(rst_list):\n if k%2==0:\n temp.append(random.randint(min([rst_list[k],rst_list[k+1]]),max([rst_list[k],rst_list[k+1]])))\n else:\n temp.append(random.randint(min(rst_list[k-1], rst_list[k]),max(rst_list[k-1], rst_list[k])))\n # 将结果temp列表,写入结果列表 rst_list\n rst_list = temp\n print(rst_list)\n # 判断37在结果列表中,则返回结果列表 rst_list\n if 37 in rst_list:\n print('rst_list:',rst_list)\n return rst_list\n else:\n # 37没在列表中,则按要求判断死循环情况(需求里的 s1=s2!=37&s3=s4!=37&s5=s6!=37 )\n # 如果进入死循环,则重新初始化结果列表 rst_list\n if rst_list[0]==rst_list[1] and rst_list[2]==rst_list[3] and rst_list[4]==rst_list[5]:\n rst_list = [random.randint(0, 100) for i in range(0, 6)]\n\ndef main():\n random_test()\n\n\nif __name__ == '__main__':\n main()\n\n```\n\n\n根据需求描述,按照最简单和容易理解的方式,逐步实现需求。注释和打印较多,实际代码篇幅并不多", + "tag_name": "python", + "python": "import random\ndef random_test():\n\trst_list = [random.randint(0,100) for i in range(0, 6)]\n\tprint(rst_list)\n\twhile 1:\n\t\ttemp = []\n\t\tfor k,v in enumerate(rst_list):\n\t\t\tif k%2==0:\n\t\t\t\ttemp.append(random.randint(min([rst_list[k],rst_list[k+1]]),max([rst_list[k],rst_list[k+1]])))\n\t\t\telse:\n\t\t\t\ttemp.append(random.randint(min(rst_list[k-1], rst_list[k]),max(rst_list[k-1], rst_list[k])))\n\t\trst_list = temp\n\t\tprint(rst_list)\n\t\tif 37 in rst_list:\n\t\t\tprint('rst_list:',rst_list)\n\t\t\treturn rst_list\n\t\telse:\n\t\t\tif rst_list[0]==rst_list[1] and rst_list[2]==rst_list[3] and rst_list[4]==rst_list[5]:\n\t\t\t\trst_list = [random.randint(0, 100) for i in range(0, 6)]\ndef main():\n\trandom_test()\nif __name__ == '__main__':\n\tmain()", + "topic_link": "https://bbs.csdn.net/topics/600469992", + "status": 1, + "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/45.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/46.json b/data_backup/python_code_json/46.json new file mode 100644 index 000000000..43670c15c --- /dev/null +++ b/data_backup/python_code_json/46.json @@ -0,0 +1,18 @@ +{ + "question_id": 7405895, + "question_title": "输入起始和结束的正整数,求其两个正整数之间的偶数和。", + "question_content": "

      输入起始和结束的正整数,求其两个正整数之间的偶数和。

      ", + "difficulty": "简单", + "answer_id": 53355299, + "answer_content": "
      \n# coding:utf-8\n\nx1 = input("请输入起始数:")\nx2 = input("请输入结束数:")\na = int(x1)\nb = int(x2)\n\n# 若a,b均为偶数时均算在内\nsum1 = 0\nfor i in range(a, b+1):\n    if i % 2 == 0:\n        sum1 += i\n        i += 2\n    else:\n        i += 1\n\n# 若a,b均为偶数时,不算a和b\nsum2 = 0\nfor i in range(a+1, b):\n    if i % 2 == 0:\n        sum2 += i\n        i += 2\n    else:\n        i += 1\n\nprint(str(a)+"到"+str(b)+"之间的偶数和(边界是偶数时算着两个边界)是:"+str(sum1))\nprint(str(a)+"到"+str(b)+"之间的偶数和(边界是偶数时不算两个边界)是:"+str(sum2))
      \n\n

       

      ", + "tag_name": "python", + "python": "x1 = input(\"请输入起始数:\")\nx2 = input(\"请输入结束数:\")\na = int(x1)\nb = int(x2)\nsum1 = 0\nfor i in range(a, b+1):\n\tif i % 2 == 0:\n\t\tsum1 += i\n\t\ti += 2\n\telse:\n\t\ti += 1\nsum2 = 0\nfor i in range(a+1, b):\n\tif i % 2 == 0:\n\t\tsum2 += i\n\t\ti += 2\n\telse:\n\t\ti += 1\nprint(str(a)+\"到\"+str(b)+\"之间的偶数和(边界是偶数时算这两个边界)是:\"+str(sum1))\nprint(str(a)+\"到\"+str(b)+\"之间的偶数和(边界是偶数时不算两个边界)是:\"+str(sum2))", + "topic_link": "https://bbs.csdn.net/topics/600470507", + "status": 1, + "keywords": "数学,奇偶数", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/46.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/47.json b/data_backup/python_code_json/47.json new file mode 100644 index 000000000..32f8445c2 --- /dev/null +++ b/data_backup/python_code_json/47.json @@ -0,0 +1,18 @@ +{ + "question_id": 7451178, + "question_title": "编程通过键盘输入每一位运动员", + "question_content": "

      体操比赛成绩统计。多名运动员,多个评委打分,去掉一个最高分和去掉一个最低分,对其余分数求平均分作为一个运动员成绩。\n编程通过键盘输入每位运动员编号和每个评委的成绩,求出运动员的最终成绩,并将运动员编号和最终成绩保存在一个字典中,形如{编号1:最终成绩1,学号2:最终成绩2.....,并将结果输出。

      ", + "difficulty": "简单", + "answer_id": 53432974, + "answer_content": "
      \nt = int(input('请输入评委人数(不得少于3人):'))\ns = int(input('请输入学生人数(不得少于1人):'))\nstus = []\nfor i in range(s):\n    stu = {'score':[]}\n    stu.update({'sn':str(input('----\\n请输入学生学号:'))})\n    for j in range(t):\n        stu['score'].append(input('请输入评委'+str(j+1)+'的评分:'))\n    stu['score'].sort()\n    stu.update({'min':stu['score'].pop(0)})\n    stu.update({'max':stu['score'].pop()})\n    stu.update({'avg':eval('+'.join(stu['score']))/len(stu['score'])})\n    stus.append(stu)\nr = {n['sn']:n['avg'] for n in stus}\nprint(r)\n
      \n\n

      使用列表stus存储所有学生成绩,每个学生的成绩信息为循环中stu词典,stu['sn']记录学号,stu['score']记录所有评委评分

      \n\n

      使用列表删除元素方式移除最高分和最低分并记录到min和max里,用剩余成绩通过字符串拼接成一个算式并运算记录到avg里

      \n\n

      最终组成输出格式信息词典,并打印

      \n", + "tag_name": "python", + "python": "t = int(input('请输入评委人数(不得少于3人):'))\ns = int(input('请输入学生人数(不得少于1人):'))\nstus = []\nfor i in range(s):\n\tstu = {'score':[]}\n\tstu.update({'sn':str(input('----\\n请输入学生学号:'))})\n\tfor j in range(t):\n\t\tstu['score'].append(input('请输入评委'+str(j+1)+'的评分:'))\n\tstu['score'].sort()\n\tstu.update({'min':stu['score'].pop(0)})\n\tstu.update({'max':stu['score'].pop()})\n\tstu.update({'avg':eval('+'.join(stu['score']))/len(stu['score'])})\n\tstus.append(stu)\nr = {n['sn']:n['avg'] for n in stus}\nprint(r)", + "topic_link": "https://bbs.csdn.net/topics/600469993", + "status": 1, + "keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/47.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/48.json b/data_backup/python_code_json/48.json new file mode 100644 index 000000000..de8173c1e --- /dev/null +++ b/data_backup/python_code_json/48.json @@ -0,0 +1,18 @@ +{ + "question_id": 7439132, + "question_title": "以特殊格式处理连续增加的数字", + "question_content": "给出一串数字, 程序要把数字按照这样的格式输出,把连续增加的数字用 [x-y] 的形式表示,只显示这一组顺序数字的首位两个数字,不连续增加的数字单独列出。 例如:\n输入:1, 2, 3, 4, 5, 8, 10, 11, 12, 13, 20, 21, 22; \n输出:[1-5] [8] [10-13] [20-22]。", + "difficulty": "简单", + "answer_id": 53412990, + "answer_content": "
      \n# -*- coding: utf-8 -*-\n# Python3\n# 输入格式:1, 2, 3, 4, 5, 8, 10, 11, 12, 13, 20, 21, 22\nseq = list(map(int, input().split(',')))\ntmp = [seq[0]]\nall_list = []\nfor n in range(len(seq)):\n    if n == len(seq) - 1:\n        all_list.append(tmp)\n        break\n    if seq[n + 1] - seq[n] == 1:\n        tmp.append(seq[n + 1])\n    else:\n        all_list.append(tmp)\n        tmp = [seq[n + 1]]\nfor a in all_list:\n    if len(a) > 1:\n        print('[%s-%s]' % (a[0], a[-1]))\n    else:\n        print('[%s]' % a[0])\n
      \n\n

       

      \n", + "tag_name": "python", + "python": "seq = list(map(int, input().split(',')))\ntmp = [seq[0]]\nall_list = []\nfor n in range(len(seq)):\n\tif n == len(seq) - 1:\n\t\tall_list.append(tmp)\n\t\tbreak\n\tif seq[n + 1] - seq[n] == 1:\n\t\ttmp.append(seq[n + 1])\n\telse:\n\t\tall_list.append(tmp)\n\t\ttmp = [seq[n + 1]]\nfor a in all_list:\n\tif len(a) > 1:\n\t\tprint('[%s-%s]' % (a[0], a[-1]))\n\telse:\n\t\tprint('[%s]' % a[0])", + "topic_link": "https://bbs.csdn.net/topics/600469994", + "status": 1, + "keywords": "排序", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/48.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/49.json b/data_backup/python_code_json/49.json new file mode 100644 index 000000000..e91192a86 --- /dev/null +++ b/data_backup/python_code_json/49.json @@ -0,0 +1,18 @@ +{ + "question_id": 7423091, + "question_title": "python 输出不重复的字符", + "question_content": "

      输入一个字符串,把最左边的10个不重复的字符(大小写算不同字符)挑选出来。 如不重复的字符不到10个,则按实际数目输出。\n输入格式:\n输入一个字符串s。\n输出格式:\n输出一个字符串,包含字符串s最左边10个不重复的字符。不到10个按实际输出。

      \n输入样例1:

      \nHello world, hello python\n

      输出样例1:

      \n
      \nHelo wrd,h
      \n

      输入样例2:

      \n
      \nsucceed
      \n

      输出样例2:

      \n
      \nsuced
      ", + "difficulty": "简单", + "answer_id": 53382491, + "answer_content": "
      \ndef unique(s):\n    set1 = set([])\n    out = ""\n    for i in range(len(s)):\n        c = s[i]\n        if c not in set1:\n            out = out + c\n            set1.add(c)\n\n    return out[0:10]\n\n\ndef main():\n    strin = "Hello world, hello python"\n    ret = unique(strin)\n    print(ret)\n\n\nif __name__ == '__main__':\n    main()\n
      \n\n

       

      ", + "tag_name": "python", + "python": "def unique(s):\n\tset1 = set([])\n\tout = \"\"\n\tfor i in range(len(s)):\n\t\tc = s[i]\n\t\tif c not in set1:\n\t\t\tout = out + c\n\t\t\tset1.add(c)\n\treturn out[0:10]\ndef main():\n\tstrin = \"Hello world, hello python\"\n\tret = unique(strin)\n\tprint(ret)\nif __name__ == '__main__':\n\tmain()", + "topic_link": "https://bbs.csdn.net/topics/600470410", + "status": 1, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/49.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/5.json b/data_backup/python_code_json/5.json new file mode 100644 index 000000000..86a31ffb7 --- /dev/null +++ b/data_backup/python_code_json/5.json @@ -0,0 +1,17 @@ +{ + "question_id": 919782, + "question_title": "二次方程式", + "question_content": "为二次方程式ax**2 + bx + c = 0 设计一个名为Equation的类,这个类包括:\n1、一个参数为a、b、c的构造方法\n2、一个名为getDeta() 的方法返回判别式的值\n3、 一个名为getRoot1()和getRoot2()的方法返回方程式的两个根,如果判别式为负,则返回0。", + "difficulty": "简单", + "answer_id": 1057528, + "answer_content": "\n```\nclass XEqu(object):\n\tdef __init__(self,a,b,c):\n\t\tself.a = a\n\t\tself.b = b\n\t\tself.c = c\n\t\n\tdef getDeta(self):\n\t\treturn pow(self.b,2)-4*self.a*self.c\n\t\t\n\tdef _is_middle(self):\n\t\tif getDeta() < 0:\n\t\t\treturn False\n\t\telse:\n\t\t\treturn True\n\t\n\tdef getRoot1(self):\n\t\tif self._is_middle():\n\t\t\treturn (-self.b+pow(getDeta(),0.5))/(2*self.a)\n\t\telse:\n\t\t\treturn 0\n\t\t\n\tdef getRoot2(self):\n\t\tif self._is_middle():\n\t\t\treturn (-self.b-pow(getDeta(),0.5))/(2*self.a)\n\t\telse:\n\t\t\treturn 0\n```\n\n大概是这样子的吧", + "tag_name": "python", + "python": "class XEqu(object):\n\tdef __init__(self,a,b,c):\n\t\tself.a = a\n\t\tself.b = b\n\t\tself.c = c\n\tdef getDeta(self):\n\t\treturn pow(self.b,2)-4*self.a*self.c\n\tdef _is_middle(self):\n\t\tif self.getDeta() < 0:\n\t\t\treturn False\n\t\telse:\n\t\t\treturn True\n\tdef getRoot1(self):\n\t\tif self._is_middle():\n\t\t\treturn (-self.b+pow(self.getDeta(),0.5))/(2*self.a)\n\t\telse:\n\t\t\treturn 0\n\tdef getRoot2(self):\n\t\tif self._is_middle():\n\t\t\treturn (-self.b-pow(self.getDeta(),0.5))/(2*self.a)\n\t\telse:\n\t\t\treturn 0\n", + "topic_link": "https://bbs.csdn.net/topics/600469982", + "status": 0, + "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/5.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/50.json b/data_backup/python_code_json/50.json new file mode 100644 index 000000000..3fbc5a323 --- /dev/null +++ b/data_backup/python_code_json/50.json @@ -0,0 +1,18 @@ +{ + "question_id": 7448359, + "question_title": "按要求实现程序功能", + "question_content": "
      1. \n\t
        1. 自定义函数ispalindrome(str):实现对参数str的判断:若是回文返回True,否则返回False
        2. 自定义函数formpalindrome(str):利用参数str生成回文:以str最后一个字符为中心,生成回文,比如“123”->“12321”;“Acdc”->“AcdcdcA
        3. 程序执行时:先使用input()函数接收一串字符,放在一个变量(比如s)中
        4. 调用自定义函数ispalindromic(),判断字符串s,根据返回的结果判断\n\t\t
          1. 如果是回文:打印“您输入的‘********’是回文!”
          2. 若不是回文:打印“您输入的‘***’不是回文!”,并调用函数formpalindromic(),生成该字符串对应的回文(见要求b),另起一行打印:“将其转变为回文的效果为:‘********’”
          \n\t\t
        \n\t
      2. 本次判断输出完毕,提示用户是否继续再来一次(Y/N)
      3. 根据用户的选择(Y/N):\n\t
        1. 不是’n’或’N’:通过外层while循环继续实现多次上述操作
        2. ‘n’或’N’    :输出 “下次再见!”,程序执行完毕
        \n\t
      \n

       

      \n

      \"\"\n 

      ", + "difficulty": "简单", + "answer_id": 53428518, + "answer_content": "
      \ndef is_palindrome(str):\n    low = 0\n    high = len(str) - 1\n\n    while low < high:\n        if str[low] != str[high]:\n            return False\n        low += 1\n        high -= 1\n    return True\ndef formpalindrome(str):\n    print('将其转变为回文的效果为')\n    for i in range(len(str) - 1):\n         print(str[i], end='')\n    print(str[::-1])\ndef ispalindromic(str):\n    if is_palindrome(str):\n        print("您输入的'"+str+"'是回文!")\n    else:\n        print("您输入的'" + str + "'不是回文!")\n        formpalindrome(str)\n\nwhile(1):\n    print("请输入一串文字:")\n    s=input()\n    ispalindromic(s)\n    print('再来一次(Y/N)')\n    c=input()\n    if c==str('n'):\n        print("下次再见!")\n        break;
      \n\n

      \"\"

      \n\n

       

      \n", + "tag_name": "python", + "python": "def is_palindrome(str):\n\tlow = 0\n\thigh = len(str) - 1\n\twhile low < high:\n\t\tif str[low] != str[high]:\n\t\t\treturn False\n\t\tlow += 1\n\t\thigh -= 1\n\treturn True\ndef formpalindrome(str):\n\tprint('将其转变为回文的效果为')\n\tfor i in range(len(str) - 1):\n\t\t print(str[i], end='')\n\tprint(str[::-1])\ndef ispalindromic(str):\n\tif is_palindrome(str):\n\t\tprint(\"您输入的'\"+str+\"'是回文!\")\n\telse:\n\t\tprint(\"您输入的'\" + str + \"'不是回文!\")\n\t\tformpalindrome(str)\nwhile(1):\n\tprint(\"请输入一串文字:\")\n\ts=input()\n\tispalindromic(s)\n\tprint('再来一次(Y/N)')\n\tc=input()\n\tif c==str('n'):\n\t\tprint(\"下次再见!\")\n\t\tbreak", + "topic_link": "https://bbs.csdn.net/topics/600470508", + "status": 0, + "keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/50.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/6.json b/data_backup/python_code_json/6.json new file mode 100644 index 000000000..468366698 --- /dev/null +++ b/data_backup/python_code_json/6.json @@ -0,0 +1,17 @@ +{ + "question_id": 7432048, + "question_title": "按照要求实现程序功能", + "question_content": "

      1. 用循环结构编写harmonic(n)函数,计算并返回第n阶调和数(1+1/2+1/3 +…+1/n)。定义主函数main(),打印输出前m个调和数。(m的值在main()函数中通过键盘输入,文件名:Harmonic.py )\n2. 用递归思想编写harmonic(n)函数,计算并返回第n阶调和数(1+1/2+1/3 +…+1/n)。定义主函数main(),打印输出前m个调和数。(m的值在main()函数中通过键盘输入,文件名:Harmonic_Recursion.py )\n3. 利用可变参数编写函数aver_nums(*b),求任意个数的数值平均值,定义主函数main(),在main()函数通过键盘输入若干学生的成绩,调用aver_nums(*b)函数求出成绩的平均分,并打印输出。 (文件名: AverScore.py )

      ", + "difficulty": "简单", + "answer_id": 53400931, + "answer_content": "
      \n# Harmonic.py\ndef harmonic(n):\n    result = 0\n    for i in range(1, n+1):\n        result += 1/i\n    return result\n\nif __name__ == '__main__':\n    m = int(input())\n    for i in range(1, m+1):\n        print(harmonic(i))\n\n# Harmonic_Recursion.py\ndef harmonic(n):\n    if n==1:\n        return 1\n    return harmonic(n-1)+1/n\n\nif __name__ == '__main__':\n    m = int(input())\n    for i in range(1, m+1):\n        print(harmonic(i))\n\n# AverScore.py  \ndef aver_nums(*b):\n    n = len(b)\n    return sum(b)/n\nif __name__ == '__main__':\n    score = input()  # 输入成绩,之间用空格隔开\n    b = [int(i) for i in score.split(' ')]\n    print(aver_nums(*b))
      \n", + "tag_name": "python", + "python": "def harmonic(n):\n\tresult = 0\n\tfor i in range(1, n+1):\n\t\tresult += 1/i\n\treturn result\nif __name__ == '__main__':\n\tm = int(input())\n\tfor i in range(1, m+1):\n\t\tprint(harmonic(i))\ndef harmonic(n):\n\tif n==1:\n\t\treturn 1\n\treturn harmonic(n-1)+1/n\nif __name__ == '__main__':\n\tm = int(input())\n\tfor i in range(1, m+1):\n\t\tprint(harmonic(i))\ndef aver_nums(*b):\n\tn = len(b)\n\treturn sum(b)/n\nif __name__ == '__main__':\n\tscore = input() \n\tb = [int(i) for i in score.split(' ')]\n\tprint(aver_nums(*b))", + "topic_link": "https://bbs.csdn.net/topics/600470400", + "status": 0, + "keywords": "算法初阶,基础知识,分治策略,用主方法求解递归式", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/6.ipynb?type=file" + } +} \ No newline at end of file diff --git a/data_backup/python_code_json/7.json b/data_backup/python_code_json/7.json new file mode 100644 index 000000000..907cb88fd --- /dev/null +++ b/data_backup/python_code_json/7.json @@ -0,0 +1,18 @@ +{ + "question_id": 7455269, + "question_title": "列表奇偶拆分", + "question_content": "

      【问题描述】\n输入一个列表,包含若干个整数(允许为空),然后将其中的奇数和偶数单独放置在一个列表中,保持原有顺序\n【输入形式】\n【输出形式】\n分两行输出,第一行输出偶数序列,第二行输出奇数序列\n【样例输入1】\n[48,82,47,54,55,57,27,73,86,14]\n【样例输出1】\n48, 82, 54, 86, 14\n47, 55, 57, 27, 73\n【样例输入2】\n[10, 22, 40]\n【样例输出2】\n10, 22, 40\nNONE\n【样例说明】\n如果奇偶拆分后,奇数列表,或者偶数列表为空,请直接输出NONE表示\n 

      ", + "difficulty": "简单", + "answer_id": 53438879, + "answer_content": "
      \nx = input()\nx1 = x.strip('[]')  # 去除输入列表字符串的[]\nx2 = x1.split(",")  # 将字符串变为列表\na = []\nb = []\nfor i in x2:\n    if int(i) % 2 == 0:\n        a.append(i)\n    else:\n        b.append(i)\nif a == []:\n    print("NONE")\nelse:\n    print(a)\nif b == []:\n    print("NONE")\nelse:\n    print(b)
      \n\n

       

      \n\n

      \"\"

      \n\n

       

      \n\n

       

      \n\n

       

      \n\n

       

      \n\n

       

      \n\n

      \"\"

      \n", + "tag_name": "python", + "python": "x = input()\nx1 = x.strip('[]') \nx2 = x1.split(\",\") \na = []\nb = []\nfor i in x2:\n\tif int(i) % 2 == 0:\n\t\ta.append(i)\n\telse:\n\t\tb.append(i)\nif a == []:\n\tprint(\"NONE\")\nelse:\n\tprint(a)\nif b == []:\n\tprint(\"NONE\")\nelse:\n\tprint(b)", + "topic_link": "https://bbs.csdn.net/topics/600470297", + "status": 1, + "keywords": "散列表,散列表,算法中阶,数据结构", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/7.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/8.json b/data_backup/python_code_json/8.json new file mode 100644 index 000000000..435ce44f1 --- /dev/null +++ b/data_backup/python_code_json/8.json @@ -0,0 +1,18 @@ +{ + "question_id": 7450673, + "question_title": "生成100个2位随机正整数", + "question_content": "

      生成100个2位随机正整数,按每行十个输出,并求出个位数字分别为0,1,2,3,4,5,6,7,8,9的正整数的个数

      ", + "difficulty": "简单", + "answer_id": 53431696, + "answer_content": "
      \n#!/usr/bin/python\n# -*- coding: UTF-8 -*-\n"""\n@author: YangPC\n@time:2021/06/16\n@QQ:327844761\n@微信公众号:ewbang\n"""\nimport random\n\n'''\n用Python生成100个2位随机正整数,按每行十个输出,并求出各位数字分别为0,1,2,3,4,5,6,7,8,9的正整数的个数\n'''\n\ndef fun():\n    random_list = [random.randint(10, 100) for n in range(100)]\n    statistics = {n: 0 for n in range(10)}\n    for index, x in enumerate(random_list):\n        print(x, end=' ')\n        statistics[int(x % 10)] = statistics[int(x % 10)] + 1\n        if ((index + 1) % 10 == 0):\n            print()\n    print(statistics)\n\n\nif __name__ == '__main__':\n    fun()\n
      \n\n

      输出结果图 

      \n\n

      \"\"

      \n", + "tag_name": "python", + "python": "import random\ndef fun():\n\trandom_list = [random.randint(10, 99) for n in range(100)]\n\tstatistics = {n: 0 for n in range(10)}\n\tfor index, x in enumerate(random_list):\n\t\tprint(x, end=' ')\n\t\tstatistics[int(x % 10)] = statistics[int(x % 10)] + 1\n\t\tif ((index + 1) % 10 == 0):\n\t\t\tprint()\n\tprint(statistics)\nif __name__ == '__main__':\n\tfun()", + "topic_link": "https://bbs.csdn.net/topics/600470401", + "status": 1, + "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/8.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file diff --git a/data_backup/python_code_json/9.json b/data_backup/python_code_json/9.json new file mode 100644 index 000000000..f2616bb86 --- /dev/null +++ b/data_backup/python_code_json/9.json @@ -0,0 +1,18 @@ +{ + "question_id": 7434772, + "question_title": "迷宫问题,需要用递归", + "question_content": "

      问题描述:一只老鼠在一个n×n迷宫的入口处,它想要吃迷宫出口处放着奶酪,问这只老鼠能否吃到奶酪?如果可以吃到,请给出一条从入口到奶酪的路径。\n思考:解决问题之前,我们首先要做的就是仔细研究问题,找出问题的已知条件和要得到的是什么。和解数学问题、物理问题一样要先弄懂问题。那么,老鼠走迷宫问题的已知条件有什么呢?\n数学模型重新定义问题:\n问题:问老鼠能否吃到奶酪就是问能否找到一条从迷宫入口到出口的路径。如果不能找到,那么老鼠就吃不到奶酪;如果能够找到,那么就给出这条路径。\n观察10×10的迷宫。这个迷宫其实是由10×10=100个格子组成的,其中绿色格子代表墙,白色格子代表路,如图(1)所示。“绿色格子代表墙,白色格子代表路”是用语言形式描述的,需要转换成数学的形式。用1和0分别定义绿色格子和白色格子,可以得到如图(2)的迷宫。\n将上面10×10的迷宫定义为如下的二维数组,即\n m[10][10]=[1,1,1,0,1,1,1,1,1,1,\n 1,0,0,0,0,0,0,0,1,1,\n 1,0,1,1,1,1,1,0,0,1,\n 1,0,1,0,0,0,0,1,0,1,\n 1,0,1,0,1,1,0,0,0,1,\n 1,0,0,1,1,0,1,0,1,1,\n 1,1,1,1,0,0,0,0,1,1,\n 1,0,0,0,0,1,1,1,0,0,\n 1,0,1,1,0,0,0,0,0,1,\n 1,1,1,1,1,1,1,1,1,1]\n有了对迷宫的数学定义,就可以很简单的定义迷宫的入口和出口了。迷宫的入口是m[0][3],出口是m[7][9]。老鼠走迷宫问题就是要找一条从入口到出口的路径,如果存在就返回这条路径;如果不存在,就返回不存在这种路径。也就是说,要在二维数组m中找一条从m[0][3]到m[7][9]全部为0的路径。\n请使用递归解决迷宫路径查找问题。\n \n

      ", + "difficulty": "困难", + "answer_id": 53405437, + "answer_content": "
      \ndef maze(m, n, route, pos, export):\n    """走迷宫\n    \n    m       - 迷宫数组,列表\n    n       - 迷宫阶数\n    route   - 可能的路线,列表\n    pos     - 当前位置,元组\n    export  - 出口位置,元组\n    """\n    \n    route.append(pos)\n    if pos == export:\n        print(route)\n    \n    if pos[0] > 0 and m[pos[0]-1][pos[1]] == 0 and (pos[0]-1,pos[1]) not in route:\n        maze(m, n, route[:], (pos[0]-1,pos[1]), export)\n    \n    if pos[0] < n-1 and m[pos[0]+1][pos[1]] == 0 and (pos[0]+1,pos[1]) not in route:\n        maze(m, n, route[:], (pos[0]+1,pos[1]), export)\n    \n    if pos[1] > 0 and m[pos[0]][pos[1]-1] == 0 and (pos[0],pos[1]-1) not in route:\n        maze(m, n, route[:], (pos[0],pos[1]-1), export)\n    \n    if pos[1] < n-1 and m[pos[0]][pos[1]+1] == 0 and (pos[0],pos[1]+1) not in route:\n        maze(m, n, route[:], (pos[0],pos[1]+1), export)\n    \n    #print('此路不通')\n    \nm = [\n    [1,1,1,0,1,1,1,1,1,1], \n    [1,0,0,0,0,0,0,0,1,1], \n    [1,0,1,1,1,1,1,0,0,1], \n    [1,0,1,0,0,0,0,1,0,1], \n    [1,0,1,0,1,1,0,0,0,1], \n    [1,0,0,1,1,0,1,0,1,1], \n    [1,1,1,1,0,0,0,0,1,1], \n    [1,0,0,0,0,1,1,1,0,0], \n    [1,0,1,1,0,0,0,0,0,1], \n    [1,1,1,1,1,1,1,1,1,1] \n]\n\nmaze(m, len(m), list(), (0,3), (7,9))
      \n\n

      运行结果:

      \n\n
      \n[(0, 3), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (2, 7), (2, 8), (3, 8), (4, 8), (4, 7), (5, 7), (6, 7), (6, 6), (6, 5), (6, 4), (7, 4), (8, 4), (8, 5), (8, 6), (8, 7), (8, 8), (7, 8), (7, 9)]
      \n\n

       

      \n", + "tag_name": "python", + "python": "def maze(m, n, route, pos, export):\n\t\"\"\"走迷宫\n\tm\t - 迷宫数组,列表\n\tn\t - 迷宫阶数\n\troute - 可能的路线,列表\n\tpos\t - 当前位置,元组\n\texport - 出口位置,元组\n\t\"\"\"\n\troute.append(pos)\n\tif pos == export:\n\t\tprint(route)\n\tif pos[0] > 0 and m[pos[0]-1][pos[1]] == 0 and (pos[0]-1,pos[1]) not in route:\n\t\tmaze(m, n, route[:], (pos[0]-1,pos[1]), export)\n\tif pos[0] < n-1 and m[pos[0]+1][pos[1]] == 0 and (pos[0]+1,pos[1]) not in route:\n\t\tmaze(m, n, route[:], (pos[0]+1,pos[1]), export)\n\tif pos[1] > 0 and m[pos[0]][pos[1]-1] == 0 and (pos[0],pos[1]-1) not in route:\n\t\tmaze(m, n, route[:], (pos[0],pos[1]-1), export)\n\tif pos[1] < n-1 and m[pos[0]][pos[1]+1] == 0 and (pos[0],pos[1]+1) not in route:\n\t\tmaze(m, n, route[:], (pos[0],pos[1]+1), export)\nm = [\n\t[1,1,1,0,1,1,1,1,1,1], \n\t[1,0,0,0,0,0,0,0,1,1], \n\t[1,0,1,1,1,1,1,0,0,1], \n\t[1,0,1,0,0,0,0,1,0,1], \n\t[1,0,1,0,1,1,0,0,0,1], \n\t[1,0,0,1,1,0,1,0,1,1], \n\t[1,1,1,1,0,0,0,0,1,1], \n\t[1,0,0,0,0,1,1,1,0,0], \n\t[1,0,1,1,0,0,0,0,0,1], \n\t[1,1,1,1,1,1,1,1,1,1] \n]\nmaze(m, len(m), list(), (0,3), (7,9))", + "topic_link": "https://bbs.csdn.net/topics/600470402", + "status": 1, + "keywords": "图算法,算法高阶,图的表示,基本的图算法", + "license": "csdn.net", + "notebook": { + "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/9.ipynb?type=file" + }, + "notebook_enable": 1 +} \ No newline at end of file -- GitLab