1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// fn build_next(s: &String) -> Vec<usize> {
// let mut v: Vec<usize> = Vec::new();
// let mut x = 1;
// let mut now = 0;
// v.push(0);
// let s_len = s.len();
// let s_chars: Vec<char> = s.chars().collect();
// while x < s_len {
// let &char_now = s_chars.get(now).take().unwrap();
// let &char_x = s_chars.get(x).take().unwrap();
// if char_now == char_x {
// v.push(now + 1);
// x = x + 1;
// now = now + 1;
// } else if now != 0 {
// now = v[now - 1]
// } else {
// v.push(0);
// x = x + 1;
// }
// }
// return v;
// }
//
// fn search(s_match: &String, s_matched: &String) -> usize {
// let v_next = build_next(s_match);
//
// let s_matched_len = s_matched.len();
// let s_matched_chars: Vec<char> = s_matched.chars().collect();
//
// let s_match_len = s_match.len();
// let s_match_chars: Vec<char> = s_match.chars().collect();
//
// let mut i = 0;
// let mut j = 0;
//
// while i < s_matched_len {
// let i_char = s_matched_chars.get(i).take().unwrap();
// let j_char = s_match_chars.get(j).take().unwrap();
// if i_char == j_char {
// i += 1;
// j += 1;
// } else if j != 0 {
// j = v_next[j - 1]
// } else {
// i += 1;
// }
// if j == s_match_len {
// println!("成功: {}", i - s_match_len);
// }
// }
//
// return i - s_match_len;
// }
use search;