Skip to content

Instantly share code, notes, and snippets.

@simias
Created Apr 25, 2021
Embed
What would you like to do?
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