QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 64 MB 満点: 100

#2046. 令人困惑的登录名

統計

Meikyokan 大学以其在计算机科学领域的科研和教育而闻名。该大学拥有一个计算机中心,配备了先进且安全的计算设施,包括超级计算机和许多连接到互联网的个人电脑。

计算机中心的一项政策是让学生选择自己的登录名。不幸的是,学生们倾向于选择相似的登录名,而因输入或指定登录名错误而导致的麻烦也相当普遍。这些麻烦给计算机中心的工作人员带来了负担。

为了避免此类麻烦,计算机中心主任 Choei Takano 博士决定杜绝相似且容易混淆的登录名。为此,Takano 需要开发一个能够检测容易混淆的登录名的程序。

基于以下四种字符串操作,两个登录名之间的距离定义为将一个登录名转换为另一个登录名所需的最少操作次数:

  1. 在任意位置删除一个字符。
  2. 在任意位置插入一个字符。
  3. 将任意位置的一个字符替换为另一个字符。
  4. 交换任意位置的两个相邻字符。

例如,“omura”和“murai”之间的距离为 2,因为可以通过以下操作序列将“omura”转换为“murai”: omura $\xrightarrow{\text{删除 'o'}}$ mura $\xrightarrow{\text{插入 'i'}}$ murai

另一个例子是“akasan”和“kaason”之间的距离也为 2: akasan $\xrightarrow{\text{交换 'a' 和 'k'}}$ kaasan $\xrightarrow{\text{将 'a' 替换为 'o'}}$ kaason

Takano 决定,距离较小的两个登录名是容易混淆的,因此必须避免。

你的任务是编写一个程序,列出所有容易混淆的登录名对。

请注意,这些规则可能会以微妙的方式结合使用。例如,“ant”和“neat”之间的距离为 2: ant $\xrightarrow{\text{交换 'a' 和 'n'}}$ nat $\xrightarrow{\text{插入 'e'}}$ neat

输入格式

输入包含多个数据集。每个数据集的格式如下:

$n$ $d$ $name_1$ $name_2$ $\dots$ $name_n$

第一个整数 $n$ 是登录名的数量。接下来是一个正整数 $d$。距离小于或等于 $d$ 的两个登录名被视为容易混淆。你可以假设 $0 < n \le 200$ 且 $0 < d \le 2$。第 $i$ 个学生的登录名由 $name_i$ 给出,仅由小写字母组成。其长度小于 16。你可以假设 $name_i$ 中没有重复项 ($1 \le i \le n$)。

输入的结束由仅包含一个零的行表示。

输出格式

对于每个数据集,你的程序应输出所有容易混淆的登录名对,每行一对,并在最后输出该数据集中容易混淆的对的总数。

在每一对中,两个登录名仅用逗号字符 (,) 分隔,且按字母顺序排列在前的登录名应首先出现。每个数据集的容易混淆对的输出必须按以下方式排序:对于两对 “$w_1,w_2$” 和 “$w_3,w_4$”,如果 $w_1$ 按字母顺序排在 $w_3$ 之前,或者它们相同且 $w_2$ 排在 $w_4$ 之前,则 “$w_1,w_2$” 必须出现在 “$w_3,w_4$” 之前。

样例

样例输入 1

8
2
omura
toshio
raku
tanaka
imura
yoshoi
hayashi
miura
3
1
tasaka
nakata
tanaka
1
1
foo
5
2
psqt
abcdef
abzdefa
pqrst
abdxcef
0

样例输出 1

imura,miura
imura,omura
miura,omura
toshio,yoshoi
4
tanaka,tasaka
1
0
abcdef,abdxcef
abcdef,abzdefa
pqrst,psqt
3

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.