当前位置:   article > 正文

994A - Fingerprints_fingerprint://uuid/b64f0ea9-a1ee-492b-96e6-ff26bff

fingerprint://uuid/b64f0ea9-a1ee-492b-96e6-ff26bff0c277
A. Fingerprints
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains two integers nn and mm (1n,m101≤n,m≤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,,xnx1,x2,…,xn (0xi90≤xi≤9) representing the sequence.

The next line contains mm distinct space-separated integers y1,y2,,ymy1,y2,…,ym (0yi90≤yi≤9) — the keys with fingerprints.

Output

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.

Examples
input
Copy
7 3
3 5 7 1 6 2 8
1 2 7
output
Copy
7 1 2
input
Copy
4 4
3 4 1 0
0 1 7 9
output
Copy
1 0
Note

In the first example, the only digits with fingerprints are 1122 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 001177 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.


题意:一个人被锁在房子里呢,门上有个锁,锁上有输入的键盘,有0到9对应的键,键盘上有一键有指纹,

现在这个人确定密码这些指纹构成的长度最长并且对应原来的子序列就能够解锁出去。

题解:模拟 暴力 由于只有10个  在原来的序列里面依次查找,带指纹的数字,有的话,就输出,并且去掉这个数字。python的话就直接找吧。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m,a[10],b[10],vis[10];
  4. int main()
  5. {
  6. cin>>n>>m;
  7. for(int i=0; i<n; i++)
  8. cin>>a[i];
  9. for(int i=0; i<m; i++)
  10. cin>>b[i];
  11. for(int i=0; i<n; i++)
  12. for(int j=0; j<m; j++)
  13. {
  14. if(!vis[b[j]]&&a[i]==b[j])
  15. cout<<b[j]<<" ",vis[b[j]]=1;
  16. }
  17. return 0;
  18. }
  1. n,m=input().split()
  2. a=input().split()
  3. b=input().split()
  4. ans=[i for i in a if i in b]
  5. print(" ".join(ans))
  1. n,m=map(int,input().split())
  2. a=input().split()
  3. b=input().split()
  4. for i in a:
  5. if i in b:
  6. print("{}".format(i),end=" ")

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/397073
推荐阅读
相关标签
  

闽ICP备14008679号