๐Ÿ“˜ Day 8 โ€“ Teacher's Day Challenge | Way Too Long Words

TanishiTanishi
2 min read

๐Ÿ—“๏ธ Date: August 01, 2025
๐Ÿงฉ Platform: Codeforces
๐Ÿ”ข Problems Solved Today: 1
๐ŸŽฏ Focus Topic: Strings, Length Checking, Abbreviation


๐Ÿ”— Table of Contents


๐Ÿงฉ 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) and at(length - 1) to access boundary letters.

  • Clean and simple loops help process input efficiently.


๐Ÿ“ˆ Daily Summary

MetricValue
Problems Solved1
Topics CoveredStrings, Abbreviation
Tools UsedC++
Next FocusArrays, Greedy Problems
Day8 / 30

๐Ÿท๏ธ Tags:
#codeforces #stringmanipulation #cpp #abbreviation #logicbuilding #43DaysChallenge

0
Subscribe to my newsletter

Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tanishi
Tanishi