Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

题目描述

image-20250325183033449

简单来讲就是需要”简化“长单词。

思路

先判断单词长度。如果小于等于10就不用管,如果超过10,则写成:首字母 + 中间的字母数量 + 末尾字母。

代码

Python

1
2
3
4
5
6
7
n = int(input())
for _ in range(n):
word = input()
if len(word) > 10:
print(word[0] + str(len(word) - 2) + word[-1])
else:
print(word)

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string.h>

int main() {
int n;
scanf("%d", &n);
char word[101];

for (int i = 0; i < n; i++) {
scanf("%s", word);
int len = strlen(word);

if (len > 10) {
printf("%c%d%c\n", word[0], len - 2, word[len - 1]);
} else {
printf("%s\n", word);
}
}

return 0;
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;

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

for (int i = 0; i < n; ++i) {
cin >> word;
int len = word.length();

if (len > 10) {
cout << word[0] << len - 2 << word[len - 1] << endl;
} else {
cout << word << endl;
}
}

return 0;
}