#P6964. [NEERC2016] Abbreviation

[NEERC2016] Abbreviation

题目描述

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 corresponding 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.

输入格式

The input file consists of up to 10001 000 lines of text with up to 120120 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.

输出格式

Write to the output file the original text with every abbreviatable sequence of words replaced with the corresponding abbreviation.

题目大意

题目描述

定义 word 为一个首字母大写、长度大于 1 、 其他位为小写字母的单词,如 AbAbcAbcd、 和 Abcde,但 abAABABcAbC

定义一个 word 串为一个有大于 1 个 word 、每两个 word 中有且只有一个空格的串,如 International Business Machines

现给你若干行,如遇到 word 串则让他变为缩写,缩写方式为:先提取首字母(大写),再加空格和 ( ,再把全称写出来,最后加上 ) ,如: International Business Machines 可缩写为 IBM (International Business Machines)

输入格式

若干行(不超过 1000 行)由大小写字母、标点和空格组成的的字符串(每行不超过 120 个字符)。

输出格式

缩写后的若干行字符串(无法缩写的不用缩写)。

translate by:ddgtang

This is ACM North Eastern European Regional Contest,
sponsored by International Business Machines.
The. Best. Contest. Ever.
A Great Opportunity for all contestants.

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.

ab Ab A Abc AB Abcd ABc Abcde AbC

ab Ab A Abc AB Abcd ABc Abcde AbC

Oh  No  Extra Spaces.And,Punctuation Ruin Everything

Oh  No  ES (Extra Spaces).And,PRE (Punctuation Ruin Everything)

提示

Time limit: 1 s, Memory limit: 512 MB.