Skip to content

Instantly share code, notes, and snippets.

@simias
Created April 25, 2021 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simias/3f0c149ffe752e0edacf19a2cc9d9716 to your computer and use it in GitHub Desktop.
Save simias/3f0c149ffe752e0edacf19a2cc9d9716 to your computer and use it in GitHub Desktop.
use std::io;
use std::io::BufRead;
fn main() -> io::Result<()> {
let mut stdin = io::BufReader::new(io::stdin());
let mut line = String::new();
loop {
line.clear();
if stdin.read_line(&mut line)? == 0 {
break;
}
for word in line.trim().split(' ').map(|word| {
let len = word.len();
if len <= 2 {
word.to_string()
} else {
let mut chars = word.chars();
let first = chars.next().unwrap();
let last = chars.last().unwrap();
format!("{}{}{}", first, len - 2, last)
}
}) {
print!("{} ", word);
}
println!("");
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment