Codeforces习题 71A Way Too Long Words

发布于 / 技术 / 0 条评论

通过读题可以得知,这个问题的主要点在于判断文字长度之后将长度大于10的字符串进行变化,不大于十的字符串则直接输出到结果中去;大于10的字符串则依据下列规则进行修改:我们写下一个单词的第一个和最后一个字母,并在它们之间写下第一个和最后一个字母之间的字母数。该数字以十进制表示,不包含任何前导零。

输入第一个为数字,之后依次输入各个字符串并进行处理,最后一并输出。

这里涉及了一个函数:

len()

他的作用就是输出一个字符串的长度,所以题目就非常简单了。

WORD_NUMBER = int(input())
tempList = []
for i in range(0,WORD_NUMBER):
    tempList.append(input())
for i in range(0,WORD_NUMBER):
    wordLen = len(tempList[i])
    if wordLen > 10:
        print(tempList[i][0]+''+str(wordLen-2)+''+tempList[i][wordLen-1])
    else:
        print(tempList[i])

代码已经通过codeforces自动检测。

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.

本网站在未特殊说明的情况下采用知识共享署名-非商业性使用-相同方式共享 3.0 协议进行许可。
<-数据丢失->