String Summarization
InterviewTime limit1sMemory limit512 MB
Given a string of sentences joined without spaces, shorten it to at most 25 characters using one of three fixed omission rules.
- Level
Medium4 of 10
- Topics
- Implementation, String, Simulation, Greedy
- Solved
- No attempts yet
Problem
Standing tall on the high Namsan
(omitted)
Build it on a rock
The ground of Seonrin
You are given one or more sentences. Write a program that summarizes the sentences to at most 25 characters by omitting a middle portion according to the rules below.
For convenience of input and output, you are given instead a string formed by concatenating the sentences with no spaces. Think of the characters from the first character of the string up to the first '.' (period) as one sentence, and the characters from the character after each '.' up to the next '.' as another sentence. For example, if the given string is 'IamInevitable.IamIronMan.', then 'IamInevitable.' is one sentence and 'IamIronMan.' is another.
The rules are as follows.
- If the length of is at most 25, print as is.
- If the length of is greater than 25, consider the part of excluding the first 11 characters and the last 11 characters. If this remaining part lies entirely within the same sentence, omit it and replace it with '...' (three '.' characters), then print.
- If neither of the above cases applies, keep only the first 9 characters and the last 10 characters of , replace the middle with '......' (six '.' characters), and print.
Input
The first line gives the length of the string.
The second line gives a string consisting of characters.
Output
Summarize to at most 25 characters according to the rules given in the problem and print the result.
Constraints
The string consists only of uppercase letters, lowercase letters, commas (,), and periods (.).
The first character of is not a period (.).
The last character of is a period (.).
Hint
The ASCII codes for uppercase letters, lowercase letters, commas, and periods are 65-90, 97-122, 44, and 46, respectively.