思路

分类讨论:

  • 统计字符串的长度,len<10len < 10 直接输出字符串;
  • 否则输出字符串的头,len2len - 2 和字符串的尾;
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;

    while (n --) {
        string str;
        cin >> str;

        int len = str.size();
        if (len < 10) {
            cout << str << endl;
        } else {
            cout << str.front() << len - 2 << str.back() << endl;
        }
    }

    return 0;
}