|
@ -2,19 +2,33 @@ |
|
|
fn main() {
|
|
|
fn main() {
|
|
|
|
|
|
|
|
|
let args = vec![
|
|
|
let args = vec![
|
|
|
"string1",
|
|
|
|
|
|
"string2",
|
|
|
|
|
|
|
|
|
"(){}[]",
|
|
|
|
|
|
"([{}])",
|
|
|
|
|
|
"(}",
|
|
|
|
|
|
"[(])",
|
|
|
|
|
|
"[({})](]",
|
|
|
];
|
|
|
];
|
|
|
|
|
|
|
|
|
println!();
|
|
|
println!();
|
|
|
|
|
|
|
|
|
for arg in args {
|
|
|
for arg in args {
|
|
|
println!("{}",func(&arg));
|
|
|
|
|
|
|
|
|
println!("{:8} => {}",arg, valid_braces(arg));
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
println!();
|
|
|
println!();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn func(s: &str) -> String {
|
|
|
|
|
|
s.into()
|
|
|
|
|
|
|
|
|
fn valid_braces(s: &str) -> bool {
|
|
|
|
|
|
let mut v = vec![];
|
|
|
|
|
|
|
|
|
|
|
|
for c in s.chars() {
|
|
|
|
|
|
match c {
|
|
|
|
|
|
'('|'{'|'[' => v.push(c),
|
|
|
|
|
|
')' => if v.pop() != Some('(') { return false },
|
|
|
|
|
|
'}' => if v.pop() != Some('{') { return false },
|
|
|
|
|
|
']' => if v.pop() != Some('[') { return false },
|
|
|
|
|
|
_ => {},
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
v.is_empty()
|
|
|
}
|
|
|
}
|