Created
April 25, 2021 15:01
-
-
Save simias/3f0c149ffe752e0edacf19a2cc9d9716 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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