#P6964. Abbreviations Replacement

    ID: 20171 Type: Default 1000ms 256MiB

Abbreviations Replacement

Abbreviations Replacement

The task is to replace each occurrence of an abbreviatable sequence of capitalized words in a given text with its abbreviation. A capitalized word is defined as an English word that starts with an uppercase letter and is followed by one or more lowercase letters (e.g. Ab, Abc, Abcd, etc.). An abbreviatable sequence is a sequence of two or more such capitalized words separated by exactly one space (with no intervening punctuation or line breaks). The abbreviation is formed by concatenating the first letters of each word, followed by a space and the full definition in parentheses. For example, the sequence Portable Network Graphics should be replaced with PNG (Portable Network Graphics).

Formally, if a sequence of words is given by (w_1, w_2, \ldots, w_k) (with (k \ge 2)) such that each (w_i) is a capitalized word, then the output replacement is: [ \text{abbr} = \bigl(\text{first letter of }w_1\bigr)\bigl(\text{first letter of }w_2\bigr)\cdots\bigl(\text{first letter of }w_k\bigr) \quad (w_1\ w_2\ \ldots\ w_k), ] where the sequence inside the parentheses is exactly as in the input.

inputFormat

The input consists of a text containing one or more lines. Each line may include upper and lower case letters, spaces, and various punctuation marks. Your program needs to process the complete text and replace every abbreviatable sequence of capitalized words (as defined above) with its corresponding abbreviation.

outputFormat

Output the modified text with all abbreviatable sequences replaced by their abbreviation followed by the full original sequence in parentheses. All other parts of the text should remain unchanged.

sample

Portable Network Graphics is used in images.
PNG (Portable Network Graphics) is used in images.