#K71407. Sentence Compression
Sentence Compression
Sentence Compression
Given a sentence, your task is to compress each word according to the following rule:
- If a word contains more than 2 alphabetical characters, replace the middle part of the word with the count of letters between its first and last character. That is, a word w of length n is transformed to w[0] (n-2) w[n-1].
- If the word has 2 or fewer characters, it remains unchanged.
Punctuation, spaces, digits and other non-alphabetical characters should be preserved in their original positions. Formally, if a character c satisfies \(\text{isalpha}(c)=true\), it is part of a word to be potentially compressed.
For example, the sentence "Hello, world! This is a test." becomes "H3o, w3d! T2s is a t2t."
inputFormat
The input consists of a single line, containing the sentence (a string) to be compressed. The sentence can include letters, digits, punctuation, and spaces.
outputFormat
Output the compressed sentence as a single line. Each word in the sentence should be transformed following the rule described above.
## sampleHello, world! This is a test.
H3o, w3d! T2s is a t2t.