Codeforces Round 65 A. Way Too Long Words(71)

本题地址:https://codeforces.com/problemset/problem/71/A

A. Way Too Long Words

Codeforces Beta Round 65 (Div. 2)

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(严格超过10) more than 10 characters.
All too long words should be replace 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.
(the number =words_length-2) (中间是字符开始和结束的长度)
That number is in decimal system and doesn't contain any leading zeroes. (这个10进制的数字,不包括全是0的数字)

Thus,'localization' will be spelt as 'l10n','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
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

Output
word
l10n
i18n
p43s

题意很明确:一个字符长度超过10,就要用缩写表示,即首字母和尾巴字母,中间是其单词的中间部分长度。

这样理解完,就很容易写了,就是简单的字符串判断,使用to_string(int)函数

代码如下

cpp 复制代码
#include <iostream>
#include <string>
using namespace std;

void solve_longwords_to_abbreviation()
{
	string str1="";
	string abbreviation="";
	string middle_value = "";
	int key1 = 2;// i=0 and i=length-1 is used

	getline(cin, str1);
	int len = str1.length();
	if (len > 10)
	{
		middle_value = to_string(len - key1);
		abbreviation = str1[0] + middle_value + str1[len - 1];

		cout << abbreviation << endl;
	}
	else
	{
		cout << str1 << endl;
	}
}
int main()
{
	int t = 0;
	cin >> t;
	getchar();
	while (t--)
	{
		solve_longwords_to_abbreviation();
	}
	return 0;
}
/*
   A. Way Too Long Words
   problemset/problem/71/A
   Codeforces Beta Round 65 (Div. 2)

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 replace 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.
(the number =words_length-2)
That number is in decimal system and doesn't contain any leading zeroes.


Thus,'localization' will be spelt as 'l10n','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
*/
相关推荐
Overboom10 小时前
[C++] --- 常用设计模式
开发语言·c++·设计模式
Univin10 小时前
C++(10.4)
开发语言·数据结构·c++
YxVoyager10 小时前
Qt C++ :QLayout 布局管理
c++·qt
KyollBM10 小时前
每日羊题 (质数筛 + 数学 | 构造 + 位运算)
开发语言·c++·算法
Univin12 小时前
C++(10.5)
开发语言·c++·算法
AA陈超12 小时前
虚幻引擎UE5专用服务器游戏开发-33 在上半身播放组合蒙太奇
c++·游戏·ue5·游戏引擎·虚幻
qq_4286396112 小时前
虚幻基础:组件间的联动方式
c++·算法·虚幻
怎么没有名字注册了啊13 小时前
C++后台进程
java·c++·算法
slim~14 小时前
CLion实现ini 解析器设计与实现
c++·后端·clion