๐ Day 8 โ Teacher's Day Challenge | Way Too Long Words


๐๏ธ Date: August 01, 2025
๐งฉ Platform: Codeforces
๐ข Problems Solved Today: 1
๐ฏ Focus Topic: Strings, Length Checking, Abbreviation
๐ Table of Contents
Daily Summary
๐งฉ Problem 1 โ Way Too Long Words
๐ Difficulty: Easy
๐ง Concepts: String Manipulation, Conditional Statements
๐ Problem Statement (Summary):
You are given n
words.
If a word has more than 10 characters, abbreviate it as:
first letter + (length - 2) + last letter
Else, print the word as it is.
Examples:
"localization"
โ"l10n"
"word"
โ"word"
(no change)
๐ก Approach:
Take input
n
for number of words.Store all words in a vector.
Loop through each word:
If its length โค 10 โ print as-is.
Else โ print first character + (length - 2) + last character.
๐งช Code (C++):
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
vector<string> words(n);
for (int i = 0; i < n; i++)
{
cin >> words[i];
}
for (int i = 0; i < n; i++)
{
if (words[i].length() <= 10)
cout << words[i] << endl;
else
{
int len = words[i].length();
cout << words[i].at(0) << len - 2 << words[i].at(len - 1) << endl;
}
}
return 0;
}
๐ธ Submission Screenshot:
๐ Example:
Input:
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
Output:
word
l10n
i18n
p43s
โ Key Takeaways:
Length-based logic is common in string problems.
length() - 2
gives characters between first and last.Use
at(0)
andat(length - 1)
to access boundary letters.Clean and simple loops help process input efficiently.
๐ Daily Summary
Metric | Value |
Problems Solved | 1 |
Topics Covered | Strings, Abbreviation |
Tools Used | C++ |
Next Focus | Arrays, Greedy Problems |
Day | 8 / 30 |
๐ท๏ธ Tags:#codeforces #stringmanipulation #cpp #abbreviation #logicbuilding #43DaysChallenge
Subscribe to my newsletter
Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
