mirror of
https://github.com/SinTan1729/unscrambler-rust.git
synced 2025-04-19 09:20:02 -05:00
Improved formatting of output
This commit is contained in:
parent
d0a4506c48
commit
e618253bc0
1 changed files with 21 additions and 6 deletions
27
src/main.rs
27
src/main.rs
|
@ -2,6 +2,9 @@ use std::io::{self, prelude::*, Write};
|
||||||
use xz2::read::XzDecoder;
|
use xz2::read::XzDecoder;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// welcome message
|
||||||
|
println!("*** Welcome to unscrambler! ***");
|
||||||
|
|
||||||
// load the compressed dictionary files (embedded in compile-time)
|
// load the compressed dictionary files (embedded in compile-time)
|
||||||
let wordlist_cmp: &[u8] = include_bytes!("dict/wordlist.txt.xz");
|
let wordlist_cmp: &[u8] = include_bytes!("dict/wordlist.txt.xz");
|
||||||
let wordlist_sorted_cmp: &[u8] = include_bytes!("dict/wordlist_sorted.txt.xz");
|
let wordlist_sorted_cmp: &[u8] = include_bytes!("dict/wordlist_sorted.txt.xz");
|
||||||
|
@ -52,17 +55,29 @@ fn main() {
|
||||||
if indices.len() == 0 {
|
if indices.len() == 0 {
|
||||||
println!("No matches found!");
|
println!("No matches found!");
|
||||||
} else {
|
} else {
|
||||||
println!("The matched words are:");
|
let mut out_list = Vec::new();
|
||||||
for index in indices {
|
for index in indices {
|
||||||
println!(
|
out_list.push(sentence_case(&wordlist[index + 1..index - 1 + input.len()]));
|
||||||
"{}",
|
}
|
||||||
sentence_case(&wordlist[index + 1..index - 1 + input.len()])
|
if out_list.len() == 1 {
|
||||||
);
|
println!("The only matched word is {}.", out_list[0]);
|
||||||
|
} else {
|
||||||
|
print!("The {} matched words are ", out_list.len());
|
||||||
|
out_list.iter().enumerate().for_each(|(pos, word)| {
|
||||||
|
print!("{}", word);
|
||||||
|
if pos < out_list.len() - 2 {
|
||||||
|
print!(", ");
|
||||||
|
} else if pos < out_list.len() - 1 {
|
||||||
|
print!(" and ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
print!(".\n");
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ask if we want to go again
|
// ask if we want to go again
|
||||||
print!("Would you like to do it again? (y/N)");
|
print!("Would you like to do it again? (y/N): ");
|
||||||
io::stdout().flush().unwrap();
|
io::stdout().flush().unwrap();
|
||||||
let mut response = String::new();
|
let mut response = String::new();
|
||||||
io::stdin().read_line(&mut response).unwrap();
|
io::stdin().read_line(&mut response).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue