CF994A.Fingerprints

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.

Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.

你被困在一个房间里,房门上有一个带有 10 个按键的数字键盘,按键分别对应数字 0 到 9。要逃出房间,你需要输入正确的密码。此外,你还拥有一串数字序列。

键盘上的某些按键留有指纹。你认为正确的密码是:你所拥有的数字序列中,最长的(不必连续的)子序列,且该子序列中只包含那些在键盘上对应按键留有指纹的数字。请找出这样的密码。

输入格式

The first line contains two integers nn and mm (1≤n,m≤101 \le n, m \le 10) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.

The next line contains nn distinct space-separated integers x1,x2,…,xnx_1, x_2, \ldots, x_n (0≤xi≤90 \le x_i \le 9) representing the sequence.

The next line contains mm distinct space-separated integers y1,y2,…,ymy_1, y_2, \ldots, y_m (0≤yi≤90 \le y_i \le 9) — the keys with fingerprints.

第一行包含两个整数 nn 和 mm(1≤n,m≤101 \le n, m \le 10),分别表示你所拥有的数字序列的位数,以及键盘上留有指纹的按键数量。

第二行包含 nn 个互不相同的、以空格分隔的整数 x1,x2,…,xnx_1, x_2, \ldots, x_n(0≤xi≤90 \le x_i \le 9),表示该数字序列。

第三行包含 mm 个互不相同的、以空格分隔的整数 y1,y2,…,ymy_1, y_2, \ldots, y_m(0≤yi≤90 \le y_i \le 9)——这些是留有指纹的按键。

输出格式

In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.

在一行中输出一个空格分隔的整数序列,表示该编码。如果所得序列为空,则不输出任何内容或仅输出一个换行符均可接受。

输入输出样例

  • 输入#1

    7 3
    3 5 7 1 6 2 8
    1 2 7

    输出#1

    7 1 2
  • 输入#2

    4 4
    3 4 1 0
    0 1 7 9

    输出#2

    1 0

说明/提示

In the first example, the only digits with fingerprints are 11, 22 and 77. All three of them appear in the sequence you know, 77 first, then 11 and then 22. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.

In the second example digits 00, 11, 77 and 99 have fingerprints, however only 00 and 11 appear in the original sequence. 11 appears earlier, so the output is 1 0. Again, the order is important.

在第一个例子中,具有指纹的数字仅有 11、22 和 77。这三个数字均出现在你所知道的序列中,顺序为:先出现 77,然后是 11,最后是 22。因此输出为 7 1 2。注意,顺序至关重要,必须与原始序列中的出现顺序一致。

在第二个例子中,数字 00、11、77 和 99 具有指纹,但只有 00 和 11 出现在原始序列中。其中 11 出现得更早,因此输出为 1 0。同样,顺序至关重要。

输入解题思路,AI测评打分。不知道怎么写?

首页