#P2525. Text Formalization

    ID: 1526 传统题 1000ms 256MiB 尝试: 1 已通过: 0 难度: 10 上传者: 标签>数据结构Alberta Collegiate Programming Contest 2003.10.18

Text Formalization

题目描述

Jimmy在ACM的一项职责是规范文本中使用的语言和语法。这项工作的一部分是展开缩略词和某些首字母缩写词

  • 缩略词(Contraction) 在英语中是通过省略或合并较长短语中的某些音节而形成的单词或短语。例如:

    • "don't" 是 "do not" 的缩略形式。
    • "o'clock" 来源于 "of the clock"。
  • 首字母缩写词(Acronym) 是由名称的首字母或一系列单词的部分组合而成的字母序列(或单词)。例如:

    • "ACM" 代表 "Association for Computing Machinery"。
    • "radar" 代表 "radio detecting and ranging"。

你的任务是读取一组缩略词和首字母缩写词的列表,并在给定的文本中展开所有缩略词和部分首字母缩写词。

输入格式

  • 输入以两个数字 C<50C < 50A<50A < 50 开头,分别表示需要展开的缩略词和首字母缩写词的数量。
  • 接下来的 CC 行每行列出一个缩略词及其展开形式。
  • 随后是 AA 行,每行列出一个首字母缩写词及其展开形式。
  • 缩略词、首字母缩写词及其展开形式均以以下格式给出:
    "缩略词或首字母缩写词" -> "展开形式"
    
    由于缩略词、首字母缩写词和展开形式可能包含空格,因此它们会被引号包围,且长度不超过8080个字符。
  • 接着是要处理的文本,每行不超过8080个字符。缩略词或首字母缩写词不会跨行出现。每个文本以单独一行#结束。

输出格式

  • 输出每个文本,仅对必要的部分进行展开:
    1. 所有缩略词必须完全展开。缩略词可能以原样、全大写或首字母大写的形式出现。展开形式应遵循相同的规则:
      • 如果缩略词是全大写的,展开形式也应全大写。
      • 如果缩略词是首字母大写的,展开形式也应首字母大写。
      • 如果有多种匹配情况,选择列表中最早匹配的规则(按“原样”、“全大写”、“首字母大写”的顺序)。
    2. 首字母缩写词仅在每个文本中第一次出现时展开。首字母缩写词的匹配必须严格区分大小写(例如 "acm" 不是 "ACM" 的实例)。展开方式为:
      • 将首字母缩写词替换为展开形式,后跟一个空格,再跟括号内的原首字母缩写词。例如:
        ACM -> Association for Computing Machinery (ACM)
        
  • 每个文本结束后输出#
  • 如果多个展开规则同时匹配,选择文本中起始位置最早的规则。如果多个规则的起始位置相同,选择输入列表中出现较早的规则。
  • 不递归处理:替换后的结果不会再次进行展开。

输入样例 1

3 2
"doesn't" -> "does not"
"isn't" -> "is not"
"can't" -> "cannot"
"ACM" -> "Association for Computing Machinery"
"CS" -> "Computing Science"
The ACM can't solve
all the problems in CS. Though large and having
many resources at its disposal, the ACM doesn't use magic. Magic isn't
part of science, and hence not part of CS. Thank you for your
suggestions.
Signed,

ACM
#
The ACM doesn't like magic.
It's not that the ACM won't use it, it's
just that the ACM doesn't understand magic.
#

输出样例 1

The Association for Computing Machinery (ACM) cannot solve
all the problems in Computing Science (CS). Though large and having
many resources at its disposal, the ACM does not use magic. Magic is not
part of science, and hence not part of CS. Thank you for your
suggestions.
Signed,

ACM
#
The Association for Computing Machinery (ACM) does not like magic.
It's not that the ACM won't use it, it's
just that the ACM does not understand magic.
#

提示

  • 缩略词和首字母缩写词的规则中,左侧部分不会互为前缀。
  • 规则不递归应用,即替换结果不会再次处理。