71A. Way Too Long Words
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
백준 21966번 문제 https://www.acmicpc.net/problem/21966 와 비슷한 느낌의 문제였다. 10글자가 넘어가면 해당 부분을 중략 처리하고 나머지는 그대로 출력하면 된다.
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL); cout.tie(NULL); std::ios::sync_with_stdio(false);
int n; cin >> n;
while (n--) {
string s; cin >> s;
if (s.size() <= 10) cout << s << "\n";
else cout << s[0] << s.size() - 2 << s[s.size() - 1] << "\n";
}
}
'학부 수업 정리 > 알고리즘연습 (22-1)' 카테고리의 다른 글
[알고연] (2주차-3) 1285B. Just Eat It! (0) | 2022.03.10 |
---|---|
[알고연] (2주차-2) 466C. Number of Ways (0) | 2022.03.10 |
[알고연] (2주차-1) 1003C. Intense Heat (0) | 2022.03.10 |
[알고연] (1주차-3) 118A. String Task (0) | 2022.03.05 |
[알고연] (1주차-1) 4A. Watermelon (0) | 2022.03.05 |