codeforces_A. Way Too Long Words

发布时间:2023年12月29日

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.

#include<stdio.h>
#include<string.h>
int main(){
	int i,j,l,n;
	char a[100];
	scanf("%d",&n);
	while(n--){
		scanf("%s",a);
		l = strlen(a);
		if(l > 10){
			printf("%c%d%c\n",a[0],l-2,a[l-1]);
		}
		else{
			puts(a);
		}
	}
	return 0;
}

ps:

思路:1.输入字符串,并获得字符串长度;

2.判断字符串长度是否大于10,如果小于等于10,输出完整字符串;如果大于10,输出第一个字符+字符串长度-2+字符串最后一个字符;

3.while(n--)使得可以判断n次,值得学习。

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?解答完毕

文章来源:https://blog.csdn.net/m0_52242197/article/details/135197532
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。