30 lines
632 B
Rust
30 lines
632 B
Rust
|
use std::io::{self, Write};
|
||
|
|
||
|
fn find_nemo(word: &str) -> Option<usize> {
|
||
|
for (i, word) in word.split(" ").enumerate() {
|
||
|
if word == "Nemo" {
|
||
|
return Some(i + 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
None
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let mut buffer = String::new();
|
||
|
|
||
|
print!("Insert your words: ");
|
||
|
io::stdout().flush().expect("Failed to flush stdout.");
|
||
|
|
||
|
io::stdin()
|
||
|
.read_line(&mut buffer)
|
||
|
.expect("Error while trying to read from stdin.");
|
||
|
|
||
|
let nemo = find_nemo(&buffer);
|
||
|
|
||
|
match nemo {
|
||
|
Some(x) => println!("I found Nemo at {}!", x),
|
||
|
None => println!("I can't find Nemo :("),
|
||
|
}
|
||
|
}
|