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 分钟前
梳理了音视频开发核心知识点
c++·音视频
专注VB编程开发20年39 分钟前
.NET Reflector反编绎,如何移除DLL中的一个公开属性
开发语言·c++·c#
落羽的落羽1 小时前
【Linux系统】C/C++的调试器gdb/cgdb,从入门到精通
linux·服务器·c语言·c++·人工智能·学习·机器学习
在下雨5991 小时前
条件变量与互斥锁复习
c++·面试
dvlinker1 小时前
使用Visual Studio中的数据断点快速定位内存越界问题的实战案例分享
c++·visual studio·memset·内存越界·栈内存越界·堆内存越界·数据断点
9ilk1 小时前
【基于one-loop-per-thread的高并发服务器】--- 项目介绍&&模块划分
运维·服务器·c++·后端·中间件
@木辛梓2 小时前
Linux 线程
linux·开发语言·c++
无语子yyds2 小时前
C++双指针算法例题
数据结构·c++·算法
羑悻的小杀马特2 小时前
ProtoBuf语法揭秘:探秘编译魔法与性能优化策略,解锁多层级选项配置的底层奥秘
c++·编程·protobuf
fpcc3 小时前
C++编程实践——eventFD
linux·c++