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
*/
相关推荐
我喜欢就喜欢33 分钟前
2025技术成长复盘:解决问题的365天
c++·qt
神仙别闹36 分钟前
基于QT(C++)+MySQL实现(窗体)学生信息管理系统
c++·qt·mysql
U-52184F691 小时前
C++ 实战:构建通用的层次化数据模型 (Hierarchical Data Model)
开发语言·c++
charlie1145141911 小时前
深入解构:MSVC 调试机制与 Visual Studio 调试器原理
c++·ide·windows·学习·visual studio·调试·现代c++
Trouvaille ~1 小时前
【C++篇】把混沌映射成秩序:哈希表的底层哲学与实现之道
数据结构·c++·stl·哈希算法·散列表·面向对象·基础入门
肆悟先生1 小时前
3.14 函数的参数传递
c++
wunianor2 小时前
[高并发服务器]DEBUG日志
linux·运维·服务器·c++
天赐学c语言2 小时前
12.19 - 买卖股票的最佳时机 && const的作用
c++·算法·leecode
.小墨迹3 小时前
C++学习之std::move 的用法与优缺点分析
linux·开发语言·c++·学习·算法·ubuntu
看见繁华4 小时前
C++ 设计模式&设计原则
java·c++·设计模式