codeforces 刷题d1

A. Way Too Long Words

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

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

题解

#include 
#include 
#include 
#include 
int main()
{
    char a[101];
    int n;
    scanf("%d",&n);
    int i;
    getchar();
    for(i=0;i10)
        {
            printf("%c%d%c\n",a[0],strlen(a)-2,a[strlen(a)-1]);
        }
        else
        puts(a);
    }
    return 0;
}
输入输出

codeforces 刷题d1_第1张图片

错误示范

#include 
#include 
#include 
#include 
int main()
{
    char a[81];//题目限制了字符长度是一到一百,应该改为a[101]
    //char a[80];在早期的C语言中,80 字符宽度被广泛用于标准文本终端的宽度。
    //这样的选择可以确保在一行上能够容纳足够的字符,以便在终端上显示文本。
    //但不适用于本道题
    int n;
    scanf("%d",&n);
    //在使用 scanf("%d", &n); 读取整数后
    //缓冲区中还留有一个回车符('\n'),而 gets(a); 会读取这个回车符
    //导致输入提前结束。
    //可以改用 getchar(); 来吸收这个回车符
    int i;
    for(i=0;i10)
        {
            printf("%c%d%c",a[0],strlen(a)-2,a[strlen(a)-1]);//这里忘记加\n
        }
        else
        puts(a);
    }
    return 0;
}
错误的输入输出

codeforces 刷题d1_第2张图片codeforces 刷题d1_第3张图片

总结:

1.注意细节。要用多少内存空间,printf()里面一定要加\n

2.遇到scanf和gets()同时存在时,要根据情况看是否要添加getchar()回收换行符

你可能感兴趣的:(c语言,c#,数据库,c语言,开发语言,算法)