QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#2057. Gmoogle

Statistics

你受聘为新的搜索引擎 GMoogle 开发 alpha 版本。该 alpha 版本需要处理以句子数据库形式呈现的内容:

  • 内容合并为一行 $S$,由字符 ‘a’-‘z’、‘A’-‘Z’、空格、标点符号(“.!?”,不计引号)和十进制数字组成。
  • 如果 $S$ 中出现字符 “.!?”,则表示句子的结束,但有一个特殊情况:如果 ‘.’ 之后的第一个非空格字符是小写英文字母,则它是一个缩写符号,而不是句子的结束;例如,字符串 “I like tea in a 500 ml. cup” 包含一个句子,而字符串 “Cup is 500 ml. I want it” 和 “Cup is 500 ml. 500 ml is great for me” 包含两个句子。
  • 句子结束后的第一个非空格字符被视为新句子的第一个字符。
  • 单词(word)是由 ‘a’-‘z’、‘A’-‘Z’ 组成的连续字符序列,由空格、标点符号或句子/字符串的开头/结尾分隔。保证数字不会与字母相邻,即类似 “10ml” 或 “R2D2” 的序列是非法的。
  • $S$ 可能包含不含单词的句子。保证 $S$ 不会连续出现两个或多个字符 “.!?”。

内容索引完成后,用户会进行查询。每个查询可以表示为一个字符串 $q$,由一个或多个单词(单词定义见上文)组成。单词由任意数量的空格(1 个或更多)分隔,可能存在前导和尾随空格。

你的程序必须打印出 $S$ 中包含 $q$ 中所有单词(顺序不限)的句子。单词比较时,如果所有对应位置的字母相同则视为相等(不区分大小写,即 ‘B’ 和 ‘b’ 被视为相同)。

输入格式

输入的第一行包含非空字符串 $S$,长度不超过 1000 个字符。下一行包含一个整数 $n$ ($1 \le n \le 100$),表示查询的数量。随后是 $n$ 个查询 $q_1, \dots, q_n$,每个查询占一行,格式如上所述。注意,$S$ 和 $q_i$ 中允许存在前导和尾随空格。

输出格式

对于每个查询 $q_1, q_2, \dots, q_n$,在单独的一行中打印查询内容。然后按其在 $S$ 中出现的顺序打印找到的句子列表,每行一个句子。查询和答案均需用引号括起来;答案前需加上一个连字符 ‘-’ 和一个空格;必须去除前导和尾随空格。请参考样例以明确格式。

样例

输入 1

Hello everyone. I want 2 coffee if
you have it. I like coffee very much.
4
HELLO
Coffee
much coffee
VoDka

输出 1

Search results for "HELLO":
- "Hello everyone."
Search results for "Coffee":
- "I want 2 coffee if you have it."
- "I like coffee very much."
Search results for "much coffee":
- "I like coffee very much."
Search results for "VoDka":

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.