Rust
use std::io::{self, prelude::*}; fn find_last_word(s: &str) -> String { s.chars() .fold(vec![], |mut last, letter| { if let Some(&c) = last.last() { if (c as u8) > (letter as u8) { last.insert(0, letter); } else { last.push(letter); } } else { last.push(letter); } last }).iter() .rev() .into_iter() .collect() } fn main() { let stdin = io::stdin(); for (i, line) in stdin.lock().lines().skip(1).enumerate() { if let Ok(text) = line { match io::stdout() .write(format!("Case #{}: {}\n", i + 1, find_last_word(&text)).as_bytes()) { Ok(_) => (), Err(why) => panic!(why), } } } }
usage: last_word(.exe) < small.in > small.txt
last_word(.exe) < small.in > small.txt
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Rust
usage:
last_word(.exe) < small.in > small.txt