C++20 sections · 1024 units
Open in Course

Way Too Long Words - Implementation

Complete solution

Here's the pseudocode:

read n
for i from 1 to n do
 read word
 if length(word) <= 10 then
 print word
 else
 print word[0] + toString(length(word) - 2) + word[length-1]
``` In C++, use word.length() or word.size() to get the string length. Access individual characters with word[0] for first and word[word.length()-1] for last. Use to_string() to convert the integer count to a string for concatenation. The + operator combines strings in C++.