Pro.ID21083 TitleStems Sell Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21083 AC0 Submit595 Ratio0.00% 时间&空间限制描述
When a word is extracted from a document and we want to check it for correct spelling, we can apply a series of rules to rewrite the word to its likely stem form. Then we check the dictionary to see if that rewritten word matches any entry in the dictionary. Natural languages are pretty messy and it may take quite a bit of experimenting to get an appropriate set. So the team has proposed a simple language for describing rewrite rules. A rule has the form pattern Apattern
For example, the pattern '*C2ies' would match any word of at least 6 characters ending in two copies of the same consonant followed by 'ies'. Thereplacement *C2ies => 122y applied to the word "berries" would match the "*" against "be", the "C" and "2" against "r", and the "ies" against "ies". In the replacement, the "1" refers to the "*" which matched "be", the "2"s each match "r", and the "y" is left as is, so the word "berries" is rewritten to "berry". Write a program to read a set of rewrite rules and to apply them to words in a paragraph of text. For each word (maximal consecutive string of alphabetic characters) in the paragraph, apply the rules, one at a time, in the order they are given, until a matching pattern is found or until all rules are exhausted. If a matching pattern is found, apply that rule to rewrite the word. If not, leave the word unchanged. 输入Input consists of multiple data sets. Each data set begins with a set of one or more rules, one per line in the format described above, followed by an empty line. This is followed by one or more lines of text, followed by an empty line or by a line containing only the left-justified string '***', which indicates end of the input. 输出Description
When a word is extracted from a document and we want to check it for correct spelling, we can apply a series of rules to rewrite the word to its likely stem form. Then we check the dictionary to see if that rewritten word matches any entry in the dictionary. Natural languages are pretty messy and it may take quite a bit of experimenting to get an appropriate set. So the team has proposed a simple language for describing rewrite rules. A rule has the form pattern Apattern
For example, the pattern '*C2ies' would match any word of at least 6 characters ending in two copies of the same consonant followed by 'ies'. Thereplacement *C2ies => 122y applied to the word "berries" would match the "*" against "be", the "C" and "2" against "r", and the "ies" against "ies". In the replacement, the "1" refers to the "*" which matched "be", the "2"s each match "r", and the "y" is left as is, so the word "berries" is rewritten to "berry". Write a program to read a set of rewrite rules and to apply them to words in a paragraph of text. For each word (maximal consecutive string of alphabetic characters) in the paragraph, apply the rules, one at a time, in the order they are given, until a matching pattern is found or until all rules are exhausted. If a matching pattern is found, apply that rule to rewrite the word. If not, leave the word unchanged. Input Input consists of multiple data sets. Each data set begins with a set of one or more rules, one per line in the format described above, followed by an empty line. This is followed by one or more lines of text, followed by an empty line or by a line containing only the left-justified string '***', which indicates end of the input. Output For each data set, print the lines of text with each word rewritten according to the given rule set, and all non-word characters left unchanged. At the end of the rewritten text for each data set, print a single line containing the left-justified string '***'. Sample Input *ed => 1 Sample Output The quick brown foxes jump over Source 样例输入*ed => 1 样例输出The quick brown foxes jump over 作者 |