diff --git a/src/SUMMARY.md b/src/SUMMARY.md index a332c63f9..f196bf079 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -406,5 +406,6 @@ - [机器人活动区域 - DFS](od/2024e200/moving-area-of-robot/index.md) - [简易压缩算法/一种字符串压缩表示的解压 - 字符串](od/2024e200/compress-string/index.md) - [智能驾驶 - 二分查找](od/2024e200/intelligent-driving/index.md) + - [字符串拼接 - 字符串](od/2024e200/merge-string/index.md) [参考资料](refs.md) diff --git a/src/od/2024e100/height-of-ternary-tree/src/main.rs b/src/od/2024e100/height-of-ternary-tree/src/main.rs index 990447dfb..4c6c1aadd 100644 --- a/src/od/2024e100/height-of-ternary-tree/src/main.rs +++ b/src/od/2024e100/height-of-ternary-tree/src/main.rs @@ -91,7 +91,7 @@ fn main() { let ret = stdin().lock().read_line(&mut line); assert!(ret.is_ok()); let num_nodes: usize = line.trim().parse().unwrap(); - assert!(1 <= num_nodes && num_nodes <= 10000); + assert!((1..=10000).contains(&num_nodes)); // 读取所有节点的值, 存放到数组 line.clear(); diff --git a/src/od/2024e100/vlan/src/main.rs b/src/od/2024e100/vlan/src/main.rs index 3602b8f49..ff05d9875 100644 --- a/src/od/2024e100/vlan/src/main.rs +++ b/src/od/2024e100/vlan/src/main.rs @@ -21,12 +21,12 @@ fn solution() { let end_id: u32 = range_part.next().unwrap().parse().unwrap(); assert!(range_part.next().is_none()); for vlan_id in start_id..=end_id { - assert!(1 <= vlan_id && vlan_id <= 4094); + assert!((1..=4094).contains(&vlan_id)); id_set.insert(vlan_id); } } else { let vlan_id: u32 = part.parse().unwrap(); - assert!(1 <= vlan_id && vlan_id <= 4094); + assert!((1..=4094).contains(&vlan_id)); id_set.insert(vlan_id); } } diff --git a/src/od/2024e200/filesystem/src/main.rs b/src/od/2024e200/filesystem/src/main.rs index c8566b3cf..811b40c40 100644 --- a/src/od/2024e200/filesystem/src/main.rs +++ b/src/od/2024e200/filesystem/src/main.rs @@ -62,7 +62,7 @@ impl FolderEntry { return None; } if self.children.contains(folder_name) { - let path = Self::to_path(&self.path, &folder_name); + let path = Self::to_path(&self.path, folder_name); Some(path) } else { None @@ -92,7 +92,7 @@ fn solution() { Some("cd") => { // 切换工作目录 if let Some(folder_name) = parts.next() { - if !parts.next().is_none() { + if parts.next().is_some() { continue; } if let Some(cwd_entry) = map.get_mut(&cwd) { @@ -105,7 +105,7 @@ fn solution() { Some("mkdir") => { // 创建子目录 if let Some(folder_name) = parts.next() { - if !parts.next().is_none() { + if parts.next().is_some() { continue; } if let Some(cwd_entry) = map.get_mut(&cwd) { diff --git a/src/od/2024e200/index.md b/src/od/2024e200/index.md index 613e4c6ac..8dd4422ed 100644 --- a/src/od/2024e200/index.md +++ b/src/od/2024e200/index.md @@ -22,3 +22,4 @@ 20. [机器人活动区域 - DFS](moving-area-of-robot/index.md) 21. [简易压缩算法/一种字符串压缩表示的解压 - 字符串](compress-string/index.md) 22. [智能驾驶 - 二分查找](intelligent-driving/index.md) +23. [字符串拼接 - 字符串](merge-string/index.md) diff --git a/src/od/2024e200/merge-string/Cargo.toml b/src/od/2024e200/merge-string/Cargo.toml new file mode 100644 index 000000000..aebc92686 --- /dev/null +++ b/src/od/2024e200/merge-string/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "e200-merge-string" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] diff --git a/src/od/2024e200/merge-string/assets/input1.txt b/src/od/2024e200/merge-string/assets/input1.txt new file mode 100644 index 000000000..603ef6237 --- /dev/null +++ b/src/od/2024e200/merge-string/assets/input1.txt @@ -0,0 +1 @@ +aab 2 \ No newline at end of file diff --git a/src/od/2024e200/merge-string/assets/input2.txt b/src/od/2024e200/merge-string/assets/input2.txt new file mode 100644 index 000000000..6275e17fd --- /dev/null +++ b/src/od/2024e200/merge-string/assets/input2.txt @@ -0,0 +1 @@ +abc 2 \ No newline at end of file diff --git a/src/od/2024e200/merge-string/assets/output1.txt b/src/od/2024e200/merge-string/assets/output1.txt new file mode 100644 index 000000000..d8263ee98 --- /dev/null +++ b/src/od/2024e200/merge-string/assets/output1.txt @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/src/od/2024e200/merge-string/assets/output2.txt b/src/od/2024e200/merge-string/assets/output2.txt new file mode 100644 index 000000000..62f945751 --- /dev/null +++ b/src/od/2024e200/merge-string/assets/output2.txt @@ -0,0 +1 @@ +6 \ No newline at end of file diff --git a/src/od/2024e200/merge-string/index.md b/src/od/2024e200/merge-string/index.md new file mode 100644 index 000000000..6e8e18b09 --- /dev/null +++ b/src/od/2024e200/merge-string/index.md @@ -0,0 +1,52 @@ +# 字符串拼接 + +## 题目描述 + +构成指定长度字符串的个数. + +给定 M (0 < M ≤ 30) 个字符 (a-z) , 从中取出任意字符 (每个字符只能用一次) 拼接成长度为 N (0 < N ≤ 5) 的字符串, +要求相同的字符不能相邻, 计算出给定的字符列表能拼接出多少种满足条件的字符串. + +输入非法或者无法拼接出满足条件的字符串则返回0. + +### 输入描述 + +给定的字符列表和结果字符串长度, 中间使用空格 ` ` 拼接 + +### 输出描述 + +满足条件的字符串个数. + +### 示例1 + +输入: + +```text +{{#include assets/input1.txt}} +``` + +输出: + +```text +{{#include assets/output1.txt}} +``` + +说明: 只能构成ab, ba. + +### 示例2 + +输入: + +```text +{{#include assets/input2.txt}} +``` + +输出: + +```text +{{#include assets/output2.txt}} +``` + +说明: 可以构成 ab ac ba bc ca cb. + +## 题解 diff --git a/src/od/2024e200/merge-string/src/main.rs b/src/od/2024e200/merge-string/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/src/od/2024e200/merge-string/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}