1 条题解
-
0
P76002 长单词缩写 — 题解
专题: 字符串
适用题目: 新生 OJ 本地题包中的 P76002,不要直接用于外站同名题。解题思路
长度不超过 10 时原样输出;更长时输出首字母、
长度 - 2、末字母。复杂度
单词总长度为 时,时间 。
易错点
中间省略的字符数不是单词总长度。
C11 参考程序
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <limits.h> int main(void) { int t; scanf("%d", &t); while (t--) { char s[105]; scanf("%104s", s); int n = (int)strlen(s); if (n > 10) printf("%c%d%c\n", s[0], n-2, s[n-1]); else puts(s); } return 0; }C++17 参考程序
#include <bits/stdc++.h> using namespace std; using ll = long long; #define nl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin>>t; while(t--){ string s; cin>>s; if(s.size()>10)cout<<s[0]<<s.size()-2<<s.back()<<nl; else cout<<s<<nl; } return 0; }
题解建议设置为训练结束后开放。普通判题无法验证是否实际使用指定函数或 STL。
- 1
信息
- ID
- 1771
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 提交数
- 1
- 已通过
- 1
- 上传者