Skip to content

Commit

Permalink
e200: Add merge string
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Sep 18, 2024
1 parent 51871de commit dd83389
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/od/2024e100/height-of-ternary-tree/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/od/2024e100/vlan/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/od/2024e200/filesystem/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/od/2024e200/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions src/od/2024e200/merge-string/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "e200-merge-string"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
1 change: 1 addition & 0 deletions src/od/2024e200/merge-string/assets/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aab 2
1 change: 1 addition & 0 deletions src/od/2024e200/merge-string/assets/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc 2
1 change: 1 addition & 0 deletions src/od/2024e200/merge-string/assets/output1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
1 change: 1 addition & 0 deletions src/od/2024e200/merge-string/assets/output2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
52 changes: 52 additions & 0 deletions src/od/2024e200/merge-string/index.md
Original file line number Diff line number Diff line change
@@ -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.

## 题解
3 changes: 3 additions & 0 deletions src/od/2024e200/merge-string/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit dd83389

Please sign in to comment.