QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 128 MB Total points: 100

#5680. You You See What?

Statistics

大约四十年前,电子邮件(即我们今天所知的电子邮件)是通过一种名为 UUCP(UNIX-toUNIX Copy Program)的协议发送的。这要求邮件发送者必须知道到达收件人路径上的每一台机器名称,并在收件人的 UUCP 邮件地址中指定这些机器名称(或称“跳数”)。这种古老的电子邮件地址被称为“bang path”。Bang path 是一个由感叹号分隔的机器名称列表,并以最后一台机器上的收件人账户名结尾。示例如下:

texasam!rice!baylor!csdept!bresearch!bpoucher

该地址告诉发送者的系统将邮件发送到 texasam 机器。texasam 机器随后将其发送到 rice 机器。rice 将其发送到 baylor 机器。baylor 将其发送到 csdept,后者将其发送到 bresearch。当邮件到达 bresearch(最后一台机器)时,它会将邮件投递给该机器上的用户 bpoucher。沿途的任何错误(未知机器、机器宕机等)都应该会发送一封电子邮件回传给发送者,说明问题所在(祝你好运)。在当时,包含八到十台机器的 bang path 并不罕见。电子邮件路由的责任在于发送者,因为他们必须知道如何通过尽可能多的跳数从自己的机器到达收件人的机器。通常,机器之间每天通过拨号调制解调器通信一到两次(当时还没有互联网),因此收件人可能需要几天时间才能收到电子邮件。

虽然在 UUCP 网络中拥有多台同名机器很常见,但不允许两台同名机器与同一台机器通信。也就是说,使用上面的例子,由于显而易见的原因,baylor 机器不能直接与两台名为 csdept 的机器通信。有时,缺乏经验的用户会在他们的 bang path 中制造“循环”:

texasam!rice!baylor!csdept!baylor!rice!dev!bresearch!bpoucher

虽然这可以工作,但它是低效的(并且会延迟电子邮件),因为 rice 机器会将邮件发送给 baylor,后者将其发送给 csdept,后者将其发回给 baylor,后者将其发回给 rice,然后 rice 再将其发送给 dev。发送到 csdept!baylor!rice 的步骤可以省略,效果相同,且电子邮件能更快到达收件人。此外,机器可能会将电子邮件转发给自己:

texasam!Rice!rice!rice!rice!rice!bpoucher

在这种情况下,除了一个 rice 跳数外,其余的都可以省略:texasam!Rice!bpoucher

对于本题,你将读取一个 bang path,移除所有不必要的跳数,并输出新的、可能更短的 bang path。

输入格式

输入包含单行字符串,即需要处理的有效 bang path。字符串长度至少为 1 个字符,且不超过 256 个字符。bang path 的每个组件(包括末尾的用户名)长度在 1 到 10 个字母数字字符之间。组件之间由单个感叹号(!)分隔。注意,机器名和用户名不区分大小写,但需要保留原始大小写。如果 bang path 不包含任何感叹号,则该单个组件指定发送者机器上的用户名。

输出格式

输出由单行字符串组成,表示输入字符串中可能更短的 bang path。如样例 2 所示,机器的大小写(baYlor)必须保留,但如果消除了一个或多个相同的机器,选择保留哪一个并不重要。

样例

样例 1

texasam!rice!baylor!csdept!baylor!rice!dev!bresearch!bpoucher
texasam!rice!dev!bresearch!bpoucher

样例 2

texasam!Rice!baYlor!csdept!BayloR!dev!Rice!bresearch!bpoucher
texasam!Rice!baYlor!dev!Rice!bresearch!bpoucher

样例 3

bresearch!bpoucher
bresearch!bpoucher

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.