Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
33
Task/ABC-Problem/Rust/abc-problem.rust
Normal file
33
Task/ABC-Problem/Rust/abc-problem.rust
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#![feature(core, unicode)]
|
||||
extern crate core;
|
||||
extern crate unicode;
|
||||
|
||||
use core::iter::repeat;
|
||||
use core::str::StrExt;
|
||||
use unicode::char::CharExt;
|
||||
|
||||
fn rec_can_make_word(index: usize, word: &str, blocks: &[&str], used: &mut[bool]) -> bool {
|
||||
let c = word.char_at(index).to_uppercase();
|
||||
for i in range(0, blocks.len()) {
|
||||
if !used[i] && blocks[i].chars().any(|s| s == c) {
|
||||
used[i] = true;
|
||||
if index == 0 || rec_can_make_word(index - 1, word, blocks, used) {
|
||||
return true;
|
||||
}
|
||||
used[i] = false;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn can_make_word(word: &str, blocks: &[&str]) -> bool {
|
||||
return rec_can_make_word(word.char_len() - 1, word, blocks, repeat(false).take(blocks.len()).collect::<Vec<_>>().as_mut_slice());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let blocks = [("BO"), ("XK"), ("DQ"), ("CP"), ("NA"), ("GT"), ("RE"), ("TG"), ("QD"), ("FS"), ("JW"), ("HU"), ("VI"), ("AN"), ("OB"), ("ER"), ("FS"), ("LY"), ("PC"), ("ZM")];
|
||||
let words = ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"];
|
||||
for word in words.iter() {
|
||||
println!("{} -> {}", word, can_make_word(word.as_slice(), blocks.as_slice()))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue