当前位置: 代码迷 >> 综合 >> Way Too Long Words
  详细解决方案

Way Too Long Words

热度:74   发布时间:2023-11-22 14:52:52.0

文章目录

  • 一、Way Too Long Words
  • 总结


一、Way Too Long Words

本题链接:Way Too Long Words

题目
A. Way Too Long Words
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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

本博客给出本题截图

在这里插入图片描述
题意:对于小于等于10长度的字符串直接输出,长度大于10的字符串输出首字符和首位字符中间的长度以及尾字符

AC代码

#include <iostream>
#include <string>using namespace std;int main()
{
    int n;cin >> n;while (n -- ){
    string a;cin >> a;if(a.size() <= 10) cout << a << endl;else{
    cout << a[0] << a.size() - 2 << a[a.size() - 1] << endl;}}return 0;
}

总结

strictly 严格地
abbreviation 缩写
consist由…构成
lowercase 小写字母
latin letters 希腊字母
possess 拥有

水题,不解释

  相关解决方案