Skip to content

Commit d11de63

Browse files
committed
chapter 12 finished
1 parent 89d0702 commit d11de63

File tree

22 files changed

+393
-0
lines changed

22 files changed

+393
-0
lines changed

chapter_11/fibonacci/Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chapter_11/fibonacci/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "fibonacci"
3+
version = "0.1.0"
4+
authors = ["Yohei Osawa <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

chapter_11/fibonacci/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let mut fibvec: Vec<i64> = Vec::new();
3+
fibvec.push(0);
4+
fibvec.push(1);
5+
for i in 2..50 {
6+
fibvec.push(fibvec[i - 1] + fibvec[i - 2]);
7+
}
8+
println!("40th value is {}", fibvec[40]);
9+
}

chapter_11/lcs/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "lcs"
3+
version = "0.1.0"
4+
authors = ["Yohei Osawa <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

chapter_11/lcs/src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::io;
2+
use std::cmp::max;
3+
4+
fn main() {
5+
let mut input_line = String::new();
6+
io::stdin().read_line(&mut input_line).unwrap();
7+
let string_a = input_line.trim().parse::<String>().ok().unwrap();
8+
input_line.clear();
9+
io::stdin().read_line(&mut input_line).unwrap();
10+
let string_b = input_line.trim().parse::<String>().ok().unwrap();
11+
let mut lcs_vec: Vec<Vec<i32>> = vec![vec![0; string_b.chars().count()]; string_a.chars().count()];
12+
let mut max_lcs = 0;
13+
for i in 1..string_a.chars().count() {
14+
for j in 1..string_b.chars().count() {
15+
if string_a.chars().nth(i) == string_b.chars().nth(j) {
16+
lcs_vec[i][j] = lcs_vec[i-1][j-1] + 1;
17+
} else {
18+
lcs_vec[i][j] = max(lcs_vec[i - 1][j], lcs_vec[i][j -1]);
19+
}
20+
max_lcs = max(max_lcs, lcs_vec[i][j]);
21+
}
22+
}
23+
println!("lcs is {}", max_lcs);
24+
}

chapter_11/matrix/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "matrix"
3+
version = "0.1.0"
4+
authors = ["Yohei Osawa <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

chapter_11/matrix/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

chapter_12/graph/Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chapter_12/graph/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "graph"
3+
version = "0.1.0"
4+
authors = ["Yohei Osawa <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
input = {path = "../../library/input"}

chapter_12/graph/input.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 2 2 4
3+
2 1 4
4+
3 0
5+
4 1 3

0 commit comments

Comments
 (0)