前些天,刚看完C++中有关string类的函数的用法,但只大概地记得那些函数有什么功能,想起要用的时候再翻开网页看怎么用。使用string类输入输出(cin、cout)字符串的确比C中输入输出字符串方便,要多次输入的时候在while后的括号里不用EOF或NULL,只需while(cin>>+string变量)即可。
#include<iostream>
#include<string>
using namespace std;
int main(){
string ch;
int n;
while(cin>>n){
while(n--){
cin>>ch;
if(ch.size()<=10)
cout<<ch<<'\n';
else
cout<<ch[0]<<ch.size()-2<<ch[ch.size()-1]<<'\n';
}
}
return 0;
}