英语题翻译26

Play on Words | JXNUOJ

Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us.
There is a large number of magnetic plates on every door. Every plate has one word written on it. The plates must be arranged into a sequence in such a way that every word begins with the same letter as the previous word ends. For example, the word ``acm'' can be followed by the word ``motorola''. Your task is to write a computer program that will read the list of words and determine whether it is possible to arrange all of the plates in a sequence (according to the given rule) and consequently to open the door.

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer number Nthat indicates the number of plates (1 <= N <= 100000). Then exactly Nlines follow, each containing a single word. Each word contains at least two and at most 1000 lowercase characters, that means only letters 'a' through 'z' will appear in the word. The same word may appear several times in the list.

Your program has to determine whether it is possible to arrange all the plates in a sequence such that the first letter of each word is equal to the last letter of the previous word. All the plates from the list must be used, each exactly once. The words mentioned several times must be used that number of times.
If there exists such an ordering of plates, your program should print the sentence "Ordering is possible.". Otherwise, output the sentence "The door cannot be opened.".

翻译:

一些秘密门包含一个非常有趣的单词谜题。考古学家团队必须解决它才能打开那扇门。因为没有其他方法可以打开门,所以拼图对我们来说非常重要。每扇门上都有大量的磁板。每个盘子上都写着一个字。必须以这样的方式将盘子排列成一个顺序,即每个单词都以与前一个单词结尾相同的字母开头。例如,单词“acm”后面可以跟单词“motorola”。你的任务是编写一个程序,该程序将读取单词列表并确定是否可以按顺序排列所有的盘子(根据给定的规则),从而打开门。

输入由 T 个测试用例组成。数量(T)在输入文件的第一行给出。每个测试用例都以包含单个整数 N 的行开始,N 表示车牌数量 (1 <= N <= 100000)。然后正好是 N 行,每行包含一个单词。每个单词包含至少两个且最多 1000 个小写字符,这意味着单词中只会出现字母“a”到“z”。同一个词可能会在列表中出现多次。

你的程序必须确定是否可以按顺序排列所有板块,以使每个单词的第一个字母等于前一个单词的最后一个字母。必须使用列表中的所有盘子,每个盘子都必须使用一次。多次提到的词必须使用该次数。如果存在这样的盘子排序,你的程序应该打印句子“Ordering is possible.”。否则,输出语句“The door cannot be opened.”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值