P4426abbreviation | |
|
Description
An abbreviation (from Latin brevis, meaning short) is a shortened form of a word or phrase. In this problem you must write an automated tool that replaces a sequence of capitalized words with the cor- responding abbreviation that consists of the first upper case letters only, followed by a full definition in parenthesis. See sample input and output.
Let us make some formal definitions. A word in a text is a maximally long sequence of lower and upper case English letters. A capitalized word is a word that consists of an upper case letter followed by one or more lower case letters. For example, “Ab”, “Abc”, “Abcd”, and “Abcde“ are all capitalized words, while “ab”, “A”, “AB“, “ABc“ and “AbC“ are not.
An abbreviatable sequence of words is a sequence of two or more capitalized words that are separated by exactly one space, no line breaks or punctuation are allowed inside it.
An abbreviation of an abbreviatable sequence of words is a sequence of the first (upper case) letters of each word, followed by a single space, an opening parenthesis, the original abbreviatable sequence, and a closing parenthesis.
Input Format
The input file consists of up to 1000 lines of text with up to 120 characters on each line. Each line consists of spaces, upper and lower case letters, commas or dots. There are no leading or trailing spaces on lines and there are no empty lines. There is at least one line in the input file.
Output Format
Write to the output file the original text with every abbreviatable sequence of words replaced with the corresponding abbreviation.
Sample Input 1
Sample Input #1:
This is ACM North Eastern European Regional Contest, sponsored by International Business Machines.
The. Best. Contest. Ever.
A Great Opportunity for all contestants.
Sample Input #2:
ab Ab A Abc AB Abcd ABc Abcde AbC
Sample Input #3:
Oh No Extra Spaces.And,Punctuation Ruin Everything
Sample Output 1
Sample Output #1:
This is ACM NEERC (North Eastern European Regional Contest), sponsored by IBM (International Business Machines).
The. Best. Contest. Ever.
A GO (Great Opportunity) for all contestants.
Sample Output #2:
ab Ab A Abc AB Abcd ABc Abcde AbC
Sample Output #3:
Oh No ES (Extra Spaces).And,PRE (Punctuation Ruin Everything)
Sample Input 2
This is ACM North Eastern European Regional Contest,
sponsored by International Business Machines.
The. Best. Contest. Ever.
A Great Opportunity for all contestants.
Sample Output 2
This is ACM NEERC (North Eastern European Regional Contest),
sponsored by IBM (International Business Machines).
The. Best. Contest. Ever.
A GO (Great Opportunity) for all contestants.
Sample Input 3
ab Ab A Abc AB Abcd ABc Abcde AbC
Sample Output 3
ab Ab A Abc AB Abcd ABc Abcde AbC
Sample Input 4
Oh No Extra Spaces.And,Punctuation Ruin Everything
Sample Output 4
Oh No ES (Extra Spaces).And,PRE (Punctuation Ruin Everything)