Skip to content

Commit ef138fd

Browse files
committed
Solved problem 'Way Too Long Words'
1 parent 5eb41e3 commit ef138fd

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

71A.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
https://codeforces.com/problemset/problem/71/A
3+
4+
Constraints:
5+
time limit per test: 1 second
6+
memory limit per test: 256 megabytes
7+
input: standard input
8+
output: standard output
9+
10+
Problem Statement:
11+
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one
12+
text is quite tiresome.
13+
14+
Let's consider a word too long, if its length is strictly more than 10 characters.
15+
All too long words should be replaced with a special abbreviation.
16+
17+
This abbreviation is made like this:
18+
We write down the first and the last letter of a word and between them we write the number of letters between the
19+
first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
20+
21+
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
22+
23+
You are suggested to automatize the process of changing the words with abbreviations.
24+
At that all too long words should be replaced by the abbreviation and the words that are not too long should not
25+
undergo any changes.
26+
27+
Input
28+
The first line contains an integer n (1≤n≤100). Each of the following n lines contains one word.
29+
All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
30+
31+
Output
32+
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
33+
34+
Examples:
35+
input
36+
4
37+
word
38+
localization
39+
internationalization
40+
pneumonoultramicroscopicsilicovolcanoconiosis
41+
42+
output
43+
word
44+
l10n
45+
i18n
46+
p43s
47+
48+
"""
49+
50+
51+
def abbreviate(word: str) -> str:
52+
"""
53+
54+
:param word: str: The string to abbreviate
55+
:return: str: abbreviated word as required
56+
"""
57+
return word if len(word) <= 10 else f"{word[0]}{len(word) - 2}{word[-1]}"
58+
59+
60+
if __name__ == '__main__':
61+
nums = int(input())
62+
words = [input() for _ in range(nums)]
63+
[print(abbreviate(word)) for word in words]

0 commit comments

Comments
 (0)