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