当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4054:KINA Is Not Abbreviation

题目描述
When introducing new terms consisting of several words, it is useful to use abbreviations. An abbreviation is a word that consists of the first letters of several consecutive words.

An abbreviation is called unambiguous if the following two conditions are satisfied:

  • It corresponds to exactly one sequence of words in a given text (although this sequence can appear in the text more than once);

  • It does not appear in the text by itself.



For example, in the text "A recursive acronym KINA means "KINA is not abbreviation"", strings "ARA" and "K" are unambiguous abbreviations, strings "A" and "KINA" are ambiguous abbreviations, and strings "RAA" and "KNA" are not abbreviations.

To introduce an abbreviation in a text, it is placed in parentheses right after the sequence of words it corresponds to. Future occurrences of this sequence of words can be replaced by the abbreviation. In the example text above, introduction of the abbreviation "K" produces the following text: "A recursive acronym KINA (K) means "K is not abbreviation"".

If two occurrences of a sequence of words overlap, only one of them can be replaced by the abbreviation. Words in a sequence are separated by one or more non-alphabetic characters. Comparison of words is case-insensitive. For example, "i18n" is an occurrence of the word sequence "I n".

The effectiveness of an abbreviation is the decrease in the number of letters after introduction of this abbreviation. Only letters are taken into account; spaces, parentheses and all other non-alphabetical characters do not count.

Given a text, find an unambiguous abbreviation with the maximum effectiveness.
输入解释
The input file contains a text with at most 4 000 characters. The text contains only characters with ASCII codes 32 (space) to 126 ("~"), 13 (carriage return), and 10 (line feed).
输出解释
If there is no unambiguous abbreviation with positive effectiveness, then the output file should contain the single number 0.

Otherwise, the first line of the output file should contain the effectiveness of the optimal abbreviation. The second line should contain the unambiguous abbreviation itself. If there are multiple unambiguous abbreviations with the maximum effectiveness, output any one of them.
输入样例
Sample Input #1

This problem name is "KINA is not abbreviation".
Once again: KINA is not abbreviation.


Sample Input #2

To be or not to be: that is the question.


Sample Input #3

Here is the chorus of the song "Jingle Bells":
Jingle bells, jingle bells,
Jingle all the way;
Oh what fun it is to ride
In a one-horse open sleigh.
输出样例
Sample Output #1

11
NA


Sample Output #2

0


Sample Output #3

16
JB
提示
In the first example, the optimal abbreviations are "NA" and "INA".
In the third example, the optimal abbreviations are "JB" and "BJ".

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-4054

最后修改于 2020-10-28T15:09:02+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536