codeforces.com71/A
Posted Pocker7
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces.com71/A相关的知识,希望对你有一定的参考价值。
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.
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.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
word题意:长度小于10的直接输出,大于十的输出第一个,中间长度,最后一个
l10n
i18n
p43s
#include<iostream> #include<string> #include<cstring> using namespace std; typedef long long ll; int main() { int n; cin>>n; string s; while(n--) { cin>>s; if(s.length()<=10) cout<<s<<endl; else{ cout<<s[0]<<s.length()-2<<s[s.length()-1]<<endl; } } return 0; }
以上是关于codeforces.com71/A的主要内容,如果未能解决你的问题,请参考以下文章
[字符串] CF-71A. Way Too Long Words
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段
CodeForces 1005D Polycarp and Div 3(思维贪心dp)
ACM问题 我的代码怎么老超时呢?? http://codeforces.com/contest/50/problem/B