这题我曾经做过一次,当时似乎写了还是有20几行的,现在会用string之后觉得真的相当容易呢。
string是有着 str.length()这样的函数可以调用的,所以我们可以很方便的获取字符串的长度,以及str[0]和str[str.length()-1]是头尾两个字符,那么这道题不就迎刃而解了吗~
需要注意的是,string是C++的库文件,cstring是C语言的哦,他们里面包含的函数是不同的呢~
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
int n; cin>>n;
for(int i=0;i<n;i++)
{
string s; cin>>s;
if(s.length()>10)cout<<s[0]<<s.length()-2<<s[s.length()-1]<<endl;
else cout<<s<<endl;
}
return 0;
}