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.
input
4 word localization internationalization pneumonoultramicroscopicsilicovolcanoconiosis
output
word l10n i18n p43s
题目要求:长度超过10的字符串只保留首尾字母,在中间加上省略掉的字母的数量;短的字符串维持原样后输出。
需要注意的地方主要有两点:
1、初始化buffer的时候需要把长度设置为101,否则当输入案例的长度n恰好为100时,buffer的末尾没有空间储存NUL字节,导致程序出错。
2、程序开头读取测试案例的个数T之后,还会残留一个换行符。所以需要在格式控制符后添加一个空格把空白符全部消除掉,或者调用getchar()函数消除这个换行符。
scanf("%d ", &T);
scanf("%d", &T);
getchar();
#include <stdio.h>
int main(void)
{
int T, p = 0;
char a[101];
scanf("%d ", &T);
while (T--)
{
gets(a, 101, stdin);
while (a[p] != NULL)
p++;
p--;
if (p < 10)
printf("%s\n", a);
else
{
printf("%c", a[0]);
printf("%d", p - 1);
printf("%c\n", a[p]);
}
p = 0;
}
return 0;
}